code.ashish.me

Atom feed

Recently added: 128 Longest Consecutive Sequence, 347 Top K Frequent Elements, 045 Jump Game 2, 228 Summary Ranges, 219 Contains Duplicate 2

030 Common Character Count

/**
 * 
 * Ashish Patel
 * e: ashishsushilPatel@gmail.com
 * w: https://ashish.me
 *
 */

 /* 
Given two strings, find the number of common characters between them.

Example

For s1 = "aabcc" and s2 = "adcaa", the output should be commonCharacterCount(s1, s2) = 3.

Strings have 3 common characters - 2 "a"s and 1 "c".
*/

function commonCharacterCount(s1, s2) {
  let count = 0
  let dict = {}
  for (let index = 0; index < s1.length; index++) {
    dict[s1[index]] = 1
  }
}

test('common Character Count', () => {
  expect(commonCharacterCount('aabcc', 'adcaa')).toEqual(3)
});

Created 2019-12-10T02:06:48+05:30, updated 2019-12-11T02:47:21+05:30 · History · Edit