Matchsticks
InterviewTime limit1sMemory limit128 MB
Given a number of matchsticks, find the smallest and largest positive numbers (no leading zero) that can be formed using exactly that many matchsticks based on per-digit costs.
- Level
Medium4 of 10
- Topics
- Dynamic programming, Greedy, Math
- Solved
- No attempts yet
Problem
Matchsticks are an ideal tool for representing numbers. Each digit of a decimal number is built from a fixed number of matchsticks according to the table below.
Given a number of matchsticks, write a program that finds the smallest number and the largest number you can build using all of the matchsticks.
Input
The first line contains the number of test cases, at most 100. Each test case consists of a single line containing the number of matchsticks . ()
Output
For each test case, print the smallest number and the largest number that can be built using all of the given matchsticks, separated by a space, on one line. Both numbers must be positive and must not start with a zero.