Given a string S representing an integer that consists of only characters ‘1’, ‘2’ and ‘3’ the task is to find the smallest number that can be formed from the string. This problem can be easily solved by using the greedy approach using the following observation: 1 and 3 cannot be swapped as their difference is 2 (which is even)

2m read time From geeksforgeeks.org
Post cover image

Sort: