Click here to Skip to main content
15,886,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
JavaScript
Input:-  
((ab)|(ba)) 2  
((a|b)*) 5  
((a*)(b(a*))) 100


Output:-
2  
32  
100


here we have Only regex(r) and string length(l) as a parameter in function.....from these two parameter we have to find count of string which is match to our regex.


What I have tried:

JavaScript
var count = 0;

for(var i=l;i>0;i--)
{

    if(r.match(l))
    {
       count++;
    }

}

console.log(count);
Posted
Updated 23-Oct-19 5:08am
Comments
F-ES Sitecore 23-Oct-19 8:44am    
Why does that input give those outputs? I don't see the relationship.
Akash Tawade 24-Oct-19 4:10am    
There ((ab)|(ba)) is a regular expression.....and 2 is fixed length of that string...we have to find count of matched length from regular expression and fixed length of string

1 solution

Go back to where you got the task, and read the instructions again.
The first regex is fixed length: if it matches with data, the match string will always be a fixed length of two characters.
The other two are variable length, and without knowing something about the data it is processing you cannot say "The matched string length will be nnn" because in the middle case it could be anything from 0 on up, and the last case "it's odd" is the only thing we can infer.

I suspect you have either missed part of the question, or not given it to us.

Either way, it's effectively homework, and we don't do that for you.
 
Share this answer
 
v2
Comments
Akash Tawade 24-Oct-19 4:11am    
I tried my best....i tried lots of thing....but it is HARD level problem from hackerrank.....I am student....this question is beyond my knowledge...that why i post here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900