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
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
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code