C2FO OnCampus sde1 question
585

You are given the following:

  • A sentence S1
  • A string S2
  • A character C that can be either 'Y or 'N
  • An integer l

A Hack number is defined as follows:

• It is the first occurrence (the index of the first character) of string S2 in sentence S1 starting from the initial position l or occurring at later positions after I depending on the value of C.

. If C is 'Y, then the matched string S2 must have a space to the left of it in sentence S1 or should be at the start of S1. It contains a space to the right of it in S1 or should be at the end of S1. In other words, the matched string must be an independent word in sentence S1.

If C is 'N, then there are no such conditions and it can also be inside any word of S1. Refer to the sample test case 2 and 3 as an example.

• If no element in S1 matches any element in S2 after the given position l, then print 'Goodbye Watson' without quotes.

Return the hack number

Comments (1)