Amazon | OA | Valid string
9660

There are 3 rules for a valid string:

  1. An empty string is valid
  2. You can add same character to a valid string X, and create another valid string yXy
  3. You can concatenate two valid strings X and Y, so XY will also be valid.
  4. Ex: vv, xbbx, bbccdd, xyffyxdd are all valid.

I tried using recursion. but could not complete all test cases. Good approaches or solutions will be helpful.

Comments (13)