Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5704 |

@Quandray | 5245 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5046 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3523 |

@mantu_singh | 3510 |

@sushant_a | 3459 |

Complete Leaderboard | |

Handle | Score |

@cfwong8 | 1134 |

@gurshehzadsingh | 676 |

@nithinreddy3210 | 610 |

@Run_for_life | 570 |

@divyagupta221100 | 557 |

@jha8768 | 553 |

@AkashLahoty | 537 |

@aayushdesai01 | 526 |

@riyakumaribkj | 524 |

@amansinha74458 | 503 |

@dreamerdreamer | 488 |

Complete Leaderboard |

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.

**Example 1:**

Input:N =6S ="234567"Output:000011Explanation: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.

**Example 2:**

Input:N =3S ="011"Output:011Explanation: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.

**Your Task:**

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)

**Constraints:**

1 <= N <= 10^{4}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

7 Segment Display

...