Encode Number - Problem
Given a non-negative integer num, return its encoding string. The encoding follows a pattern where each number maps to a binary-like representation.
The encoding pattern can be deduced from these examples:
0 → ""(empty string)1 → "0"2 → "1"3 → "00"4 → "01"5 → "10"6 → "11"
Your task is to find the pattern and implement the encoding function.
Input & Output
Example 1 — Small Number
$
Input:
num = 5
›
Output:
"10"
💡 Note:
Number 5 belongs to group 2 (range 3-6), at position 1 within the group. Position 1 in 2-bit binary is "10".
Example 2 — Edge Case Zero
$
Input:
num = 0
›
Output:
""
💡 Note:
Zero maps to empty string according to the encoding pattern.
Example 3 — Group Boundary
$
Input:
num = 3
›
Output:
"00"
💡 Note:
Number 3 is the first in group 2, at position 0. Position 0 in 2-bit binary is "00".
Constraints
- 0 ≤ num ≤ 109
Visualization
Tap to expand
Understanding the Visualization
1
Input
Given number num = 5
2
Pattern
Identify groups: 0→"", 1-2→1bit, 3-6→2bit, 7-14→3bit
3
Output
Encoded string "10"
Key Takeaway
🎯 Key Insight: Numbers are grouped by powers of 2, with each group using binary encoding of specific bit length
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code