Ctrl K

Numbers Made of Fours and Sevens

Medium
Consider the positive numbers whose decimal form uses only the digits 4 and 7: 4, 7, 44, 47, 74, 77, 444, and so on. Return the k-th smallest such number (counting from one) as a string.
Example 1
k=5 → '74'

In increasing order: 4, 7, 44, 47, 74, ... The fifth one is 74.

Example 2
k=2 → '7'

The second smallest is 7.

Example 3
k=14 → '777'

Six numbers have one or two digits, then come eight three-digit ones; the 14th is the last of those, 777.

Constraints
  • 1 ≤ k ≤ 10¹⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsCode by Its Position MediumSum of Binary Strings EasyNumber in Roman Numerals MediumDivision Without Dividing MediumMultiplying Digit Strings Medium
loading Python…
Input
k=5
Expected
'74'

Run checks the first 3 tests in your browser. Submit checks all 100 tests on the server, hidden ones included.