code.ashish.me

Atom feed

Recently added: 02 Count Of Subset Sum, 416 Partition Equal Subset Sum, 01 Subset Sum, 518 Coin Change 2, 983 Minimum Cost For Tickets

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-10T01:54:48+05:18, updated 2019-12-11T02:35:21+05:18 · History · Edit