ajayg415 / Javascript-Algorithms

1 stars 0 forks source link

Problem 3: Binary pattern Match #1

Closed krishna63 closed 4 years ago

krishna63 commented 4 years ago

Problem: Binary match pattern is kind of search which returns the number of times the pattern is matched in a given string.

Write a function which returns the number of times the pattern is matched in a given string. The pattern will be in binary format meaning combination of 0 and 1's.

Rules: if the number is 0 in the pattern then it should be vowel and if the number is 1 then it should be consonant. Searching string will be of lower case only and will be of one word only. Pattern will be in a string.

Example 1: : Input : Pattern: '010', Search String: 'amazing' Output: 2

Explanation: In the above pattern first and last numbers are zero's so the letters should start and end with vowel and as the second number is 1, the middle letter is consonant. So the function should search for such kind of words in the word and return the count. In the above given input it matches only twice and they are:

  1. 'ama'
  2. 'azi'

Example 2: Input: Pattern: 100, Search String : 'seesaw' Output: 1

Matches are:

  1. 'see'
function binaryMatchPattern(searchString, pattern) {
     // write the code over here

}
ajayg415 commented 4 years ago

Thanks for adding this, a really good one. I'll work on this.

ajayg415 commented 4 years ago

Merged the code and added solution.