Using seven segment display, you can write down any digit from 0 to 9 using at most seven segments. Given a positive number N and then a string S representing a number of N digits. You have to rearrange the segments in this N digit number to get the smallest possible N digit number. This number can have leading zeros. You can not waste any segment or add any segment from your own. You have to use all of the segments of the given N digits.
Input: N = 6 S = "234567" Output: 000011 Explanation: 234567 has a total of 28 segments and we can rearrange them to form 000011 which has 28 segments too. 000011 is the smallest possible number which can be formed on rearrangement.
Input: N = 3 S = "011" Output: 011 Explanation: 011 has a total of 10 segments and this is the smallest number with 10 segments. which has 28 segments too. 000011 is the smallest possible number which can be formed on rearrangement.
You don't need to read input or print anything. Your task is to complete the function sevenSegments() which takes an Integer N and a String S of length N as input and returns the smallest possible N digit number which can be made using all of the segments given.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
1 <= N <= 104
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?Yes