We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Assume our string is "papahopackerank"
So we will be looping the above string
foriin"papahopackerank"
Initially a = 0 means "hackerrank"[0] = "h"
In our for loop once we find a "h" we will increase a. "papa" is completely ignored
After finding "h" it will increase a and now "hackerrank"[1] = "a" which means it will start searching "a" in rest of the string then "c" then "k" up to the end.
if a becomes 9 we can just break the loop and print "YES". Since a = 9 means we have found all letters of hackerrank.
In our example string, a will become 5 since it will match only up to "hacker". So our program will print "No"
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
HackerRank in a String!
You are viewing a single comment's thread. Return to all comments →
Yes sure.
Assume our string is "papahopackerank" So we will be looping the above string
Initially a = 0 means "hackerrank"[0] = "h"
In our for loop once we find a "h" we will increase a. "papa" is completely ignored
After finding "h" it will increase a and now "hackerrank"[1] = "a" which means it will start searching "a" in rest of the string then "c" then "k" up to the end.
if a becomes 9 we can just break the loop and print "YES". Since a = 9 means we have found all letters of hackerrank.
In our example string, a will become 5 since it will match only up to "hacker". So our program will print "No"