Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
655 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 (143,680 points) | 655 views

Please log in or register to answer this question.