Education + Jobs Hiring Website - 2025
0 like 0 dislike
829 views

There are three robots named Ray , Ben and Kevin.Initially Ray has a string S of length N , while the other two robots have empty strings. We can make either of the following moves:

  • Move1: Remove the first character from Ray's string and append it to the Ben's string.
  • Move2: Remove the last character from Ben's string and append it to the Kevin's string.

You must perform either of the two moves mentioned above in such a way that the string left with Ray and Ben are empty and the string left with Kevin is lexicographically the smallest. Your task is to return this lexicographically smallest string that Kevin has after completing this activity.

Output Specification:
A string value denoting the string left with Kevin which is lexicographically the smallest.

Example 1

  • Input : dad
  • output : add
in Online Assessments by Expert (145,060 points) | 829 views

Please log in or register to answer this question.