Swiggy | SDE-2 | Hackerrank OA | Flexible Strings
Anonymous User
9615

Given a string abccc,
Given are below operations

  1. b can be replaced by c
  2. a can be replaced by b

Can the given string converted to all of the same charcters?
The string abccc can be converted to ccccc by following operations:

  1. Convert b at index 1 to c
  2. Convert a at index 0 to b
  3. Convert b at index 0 to c

The given operations can be performed infinite number of times on the string. We need to find whether the string can be converted to a string containing all same characters.

Note : the operations can be performed in any order and any number of times.

Example 1:
Input :
String - abccc
Operations -

  1. b --> c
  2. a --> b

Output - YES

Example 2:
String - abcdc
Operations:

  1. b --> c
  2. a --> d

Output - NO

Comments (13)