ELab in a String!

QUESTION

We say that a string, s, contains the word ELab if a subsequence of the characters in s spell the word ELab. For example, ulcEElLab does contain ELab, but ulceLarfb does not .\n\nMore formally, let p0,p1,…,p3 be the respective indices of E, L, a,b in string s. If p0<p1<p2<p3 is true, then s contains ELab.\n\nYou must answer q queries, where each query i consists of a string, si. For each query, print YES on a new line if si contains eLab; otherwise, print NO instead.\n\nInput Format\n\nThe first line contains an integer denoting q(the number of queries). \nEach line i of the q subsequent lines contains a single string denoting si.\n\nConstraints\n2<=q<=10^2 10<=|si|<=10^4\nOutput Format\n\nFor each query, print YES on a new line if si contains hackerrank; otherwise, print NO instead.

ANSWER

#include <stdio.h>
#include<string.h>
int main()
{
  int t,i,j,cnt,l,l1;
  char s[20],str[]="ELab";
 scanf("%d",&t);
  while(t)
  {
    cnt=0;
    scanf("%s",s);
    l=strlen(s);
    l1=strlen(str);
    while(i<l1 && j<l)
    {
      if(str[i]==s[j])
      {
        i++;
        cnt++;
      }
      else
      {
        j++;
      }
    }
    if(cnt>=l1)
      printf("YES\n");
    else
      printf("NO\n");
    t--;
  }   
          
	return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
CHP Adblock Detector Plugin | Codehelppro