Connection Status:
Competition Arena > LoopsyDoopsy
SRM 763 · 2019-07-16 · by abdullahkool768 · Greedy
Class Name: LoopsyDoopsy
Return Type: String
Method Name: getSmallestNumber
Arg Types: (int)
Problem Statement

Problem Statement

The number of loops in a digit is the number of closed regions you produce when you write the digit on paper. For example, "1" has no loops, "9" has one loop, and "8" has two. (As the number of loops depends on the font you use, the exact numbers of loops we are using in this problem are given in the Notes.)

By extension, the number of loops in any nonnegative integer is the total number of loops in its individual digits. For example, "2461" has two loops and "1890" has four.

You are given the int loops. Find the smallest nonnegative integer with exactly loops loops and return it as a String. Note that the returned String cannot have unnecessary leading zeros.

Notes

  • The digits 0 through 9 have 1, 0, 0, 0, 1, 0, 1, 0, 2, and 1 loops, respectively.

Constraints

  • loops will be between 1 and 2,500, inclusive.
Examples
0)
1
Returns: "0"

0, 4, 6, 9, 10, 24 are some of the non-negative integers with exactly 1 loop.

1)
2
Returns: "8"

8, 49, 66, 100 are some of the non-negative integers with exactly 2 loops.

2)
3
Returns: "48"
3)
2
Returns: "8"
4)
15
Returns: "48888888"
151)
40
Returns: "88888888888888888888"

Watch out for integer overflow.

Submissions are judged against all 157 archived test cases, of which 6 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class LoopsyDoopsy with a public method string getSmallestNumber(int loops) · 157 test cases · 2 s / 256 MB per case

Submitting as anonymous