Base 7 - Problem
Given an integer num, return a string of its base 7 representation.
Base 7 uses digits 0-6, where each position represents a power of 7. For example, the number 100 in base 10 equals 2*7² + 0*7¹ + 2*7⁰ = 202 in base 7.
Input & Output
Example 1 — Positive Number
$
Input:
num = 100
›
Output:
"202"
💡 Note:
100 ÷ 7 = 14 remainder 2, 14 ÷ 7 = 2 remainder 0, 2 ÷ 7 = 0 remainder 2. Reading remainders from bottom to top: "202"
Example 2 — Negative Number
$
Input:
num = -7
›
Output:
"-10"
💡 Note:
Convert absolute value: 7 ÷ 7 = 1 remainder 0, 1 ÷ 7 = 0 remainder 1. Result is "10", add minus sign: "-10"
Example 3 — Zero
$
Input:
num = 0
›
Output:
"0"
💡 Note:
Special case: 0 in any base is "0"
Constraints
- -107 ≤ num ≤ 107
Visualization
Tap to expand
Understanding the Visualization
1
Input
Decimal number (e.g., 100)
2
Process
Repeated division by 7, collecting remainders
3
Output
Base 7 string ("202")
Key Takeaway
🎯 Key Insight: Base conversion uses repeated division - remainders become digits in reverse order
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code