Help me in solving VOWMTRX problem

My issue

can you give reason why my code is failed?

My code

//Radhe Radhe
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int M = 1e9 + 7;
bool isVowel(char &x){
    if(x =='a'|| x=='e'||x=='i'||x=='o'||x=='u')return true;
    return false;
}
void Radhe(){
 ll t;
 cin>>t;
 while(t--){
     int n,k;
     cin>>n>>k;
     string s;
     cin>>s;
     vector<int>ans;
     int j = 0;
     for(int i=0;i<n;i++){
        if(isVowel(s[i])){
             j++;
        }
        if(j==k){
            i++;
            int curr = 0;
            while(i<n && !isVowel(s[i])){
                curr++;
                i++;
            }
            if(i!=(n-1)){
            // i--;
                ans.push_back(curr+1);
            }
            j=0;
        }
     }
    //  for(auto x:ans)cout<<x<<" ";
    //  cout<<endl;
     long long int res = 1;
     for(auto x:ans){
        res = ((res%M )*(x%M ))%M;
     }
     cout<<res<<endl;
 }
}
int main(){
Radhe();
return 0;
}

Problem Link: The Vowel Matrix Practice Coding Problem - CodeChef

@jaggadaku005
plzz refer my c++ code

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    long long int n,k;
	    cin>>n>>k;
	    string s;
	    cin>>s;
	    long long int mod=1e9+7;
	    long long int ans=1,cnt=0;
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u')
	        {
	            cnt++;
	        }
	        if(cnt==k)
	        {
	            int j=i+1;
	            long long int cnt1=1;
	            while(j<n)
	            {
        	        if(s[j]=='a'||s[j]=='e'||s[j]=='i'||s[j]=='o'||s[j]=='u')
        	        {
        	            break;
        	        }
        	        else
        	        cnt1++;
        	        j++;
	            }
	            
	            i=j-1;
	            if(j!=n)
	            ans=(ans*cnt1)%mod;
	            cnt=0;
	        }
	    }
	    cout<<ans<<endl;
	}
}
1 Like

actually i forget to decrement index after while loop.