Problem Solution

1 solutions

  • 1
    @ 2024-12-12 16:31:24

    Problem Setter : Kamonasish Roy (Bullet)

    Problem tag : Two pointer, Bruteforce.
    Tutorial: You need to check if “SeriousOJ” exists as a subsequence of the given string S.
    Let's see, string p =”SeriousOJ”.
    L=0, index represents string P, and R=0, index represents given string S.
    Just travel R up to string length S: when S[R] is equal to P[L], increase the L value. Once you get L equal to the length of string P, the answer exists.
    Time complexity : O(|S|)

    #include<bits/stdc++.h>
    using namespace std;
    const long long M=2e5+10,MOD=1000000007;
    typedef long long ll;
    
    
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int t=1;
        cin>>t;
        while(t--){
            int n;
            cin>>n;
            string s;
            cin>>s;
            int l=0;
            string p="SeriousOJ";
            for(char ch:s){
                if(ch==p[l])l++;
                if(l==p.size())break;
            }
            cout<<(l==p.size()?"YES\n":"NO\n");
       
         
    
        
        
    }
    
        
        return 0;
     
    }
    
  • 1

Information

ID
1147
Difficulty
1
Category
(None)
Tags
(None)
# Submissions
95
Accepted
71
Accepted Ratio
75%
Uploaded By