Find The K-th Lucky Number - Problem

We know that 4 and 7 are lucky digits. Also, a number is called lucky if it contains only lucky digits.

You are given an integer k, return the k-th lucky number represented as a string.

Note: Lucky numbers are ordered as: 4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777, ...

Input & Output

Example 1 — Basic Case
$ Input: k = 4
Output: "47"
💡 Note: Lucky numbers in order: 4(1st), 7(2nd), 44(3rd), 47(4th). The 4th lucky number is "47".
Example 2 — Single Digit
$ Input: k = 1
Output: "4"
💡 Note: The very first lucky number is "4".
Example 3 — Larger Number
$ Input: k = 8
Output: "444"
💡 Note: Lucky numbers: 4, 7, 44, 47, 74, 77, 444, 447. The 8th is "444".

Constraints

  • 1 ≤ k ≤ 109

Visualization

Tap to expand
Find The K-th Lucky Number (k=4)Lucky digits: 4 and 7 only47444774771st2nd3rd4th5th6thPattern: Binary-like sequence with digits 4 and 7k=4 → Output: "47"
Understanding the Visualization
1
Input
Given k=4, find 4th lucky number
2
Process
Lucky numbers: 4, 7, 44, 47, 74, 77, ...
3
Output
4th lucky number is "47"
Key Takeaway
🎯 Key Insight: Lucky numbers follow binary pattern where 0 maps to 4 and 1 maps to 7
Asked in
Google 15 Microsoft 12
25.0K Views
Medium Frequency
~15 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen