Thousand Separator - Problem
You're given an integer
For example, the number
Goal: Transform any integer into a properly formatted string with dots separating every three digits from right to left.
Examples:
•
•
•
n and need to format it as a human-readable number by adding dots (".") as thousand separators. This is similar to how large numbers are displayed in many European countries or financial systems.For example, the number
1234567 should become "1.234.567" - much easier to read at a glance!Goal: Transform any integer into a properly formatted string with dots separating every three digits from right to left.
Examples:
•
n = 987 → "987" (no separator needed)•
n = 1234 → "1.234"•
n = 123456789 → "123.456.789" Input & Output
example_1.py — Python
$
Input:
n = 987
›
Output:
"987"
💡 Note:
The number is less than 1000, so no thousand separator is needed. We simply return the number as a string.
example_2.py — Python
$
Input:
n = 1234
›
Output:
"1.234"
💡 Note:
We need to separate the thousands: 1 (thousand) and 234 (remainder), resulting in '1.234'.
example_3.py — Python
$
Input:
n = 123456789
›
Output:
"123.456.789"
💡 Note:
This large number needs multiple separators: 123 (millions), 456 (thousands), and 789 (remainder).
Constraints
- 0 ≤ n ≤ 231 - 1
- n is a non-negative integer
- The result should use dot (.) as separator
Visualization
Tap to expand
Understanding the Visualization
1
Start with Number
Take the input number 1234567
2
Convert to String
Transform to string '1234567' for easy manipulation
3
Group from Right
Count positions from right: 567 (pos 0-2), 234 (pos 3-5), 1 (pos 6)
4
Insert Separators
Add dots between groups: 1.234.567
Key Takeaway
🎯 Key Insight: Process digits from right to left and insert separators every 3 positions to create readable number formatting
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code