Thousand Separator - Problem
Given an integer n, add a dot (".") as the thousands separator and return it in string format.
The thousands separator should be placed every three digits from the right.
Examples:
1234becomes"1.234"987654321becomes"987.654.321"123becomes"123"(no separator needed)
Input & Output
Example 1 — Basic Case
$
Input:
n = 987
›
Output:
"987"
💡 Note:
Number has 3 digits, so no separator needed
Example 2 — Four Digits
$
Input:
n = 1234
›
Output:
"1.234"
💡 Note:
Insert dot after first digit: 1 and 234
Example 3 — Large Number
$
Input:
n = 123456789
›
Output:
"123.456.789"
💡 Note:
Two dots needed: 123, 456, and 789 are each 3-digit groups
Constraints
- 0 ≤ n ≤ 231 - 1
Visualization
Tap to expand
Understanding the Visualization
1
Input
Integer number like 1234567
2
Process
Group digits by 3 from right, insert dots
3
Output
Formatted string "1.234.567"
Key Takeaway
🎯 Key Insight: Group digits from right to left in sets of 3, inserting separators between groups
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code