11/27/2023 0 Comments Convert string to long hackerrankIf a becomes 9 we can just break the loop and print "YES". "papa" is completely ignoredĪfter finding "h" it will increase a and now "hackerrank" = "a" which means it will start searching "a" in rest of the string then "c" then "k" up to the end. In our for loop once we find a "h" we will increase a. So we will be looping the above string for i in "papahopackerank" Without using regex def hackerrankInString(s): So it matches any word that has hackerrank in it such as s ="h-ac++ke-zzz-r-ra?nk" * - means "0 or more instances of the preceding regex token" * just means "0 or more of any character" Return "YES" if re.search(".*".join(list("hackerrank")), s) else "NO"Ĭreates the following regex pattern 'h.*a.*c.*k.*e.*r.*r.*a.*n.*k' Rhbaasdndfsdskgbfefdbrsdfhuyatrjtcrtyytktjjt does not contain the last three characters of hackerrank, so we print NO on a new line.Because the string contains all the characters in hackerrank in the same exact order as they appear in hackerrank, we print YES on a new line. The characters of hackerrank are bolded in the string above. įor each query, print YES on a new line if contains hackerrank, otherwise, print NO. The first line contains an integer, the number of queries.Įach of the next lines contains a single query string. HackerrankInString has the following parameter(s): If is true, then contains hackerrank.įor each query, print YES on a new line if the string contains hackerrank, otherwise, print NO.Ĭomplete the hackerrankInString function in the editor below. More formally, let be the respective indices of h, a, c, k, e, r, r, a, n, k in string. If we reorder the first string as, it no longer contains the subsequence due to ordering. In the second case, the second r is missing. For example, if string it does contain hackerrank, but does not. We say that a string contains the word hackerrank if a subsequence of its characters spell the word hackerrank.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |