CR194 - Editorial

Problem Link:

Contest
Practice

Author: Vaibhav Srivastava
Editorialist: Saurabh Kumar

Difficulty:

cakewalk

Problem:

We have given a string S and we have to output “yes” if any of the sub-sequence of that string forms the word “codered” else output “no”.

Explanation:

Sub-sequence - A sub-sequence is a sequence which can be derived from another sequence by removing zero or more elements, without changing the order of the remaining elements.

Example- Sub-sequence(abc) = {a, b, c, ab, ac, bc, abc}

This problem has a very straight-forward and simple implementation. Take two pointers one for the string S and other for the string “codered” (say str) namely i and j respectively.
Now iterate through the string and check for s[i] == str[j], if this is true, increase j by 1. If j becomes 7 then output “yes” else output “no”.

Time Complexity is O(N) where N is the size of the string S.

My approach

Algo:

   ans = "No"
    pop from given string
       if popped char is same as last char of "CODERED" or whatever remains of "CODERED"
            pop from remains of "CODERED"
            if remains == 0:
               ans =  "Yes" and break
    print(ans)

My practice submission
link text

//