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:

  • 1234 becomes "1.234"
  • 987654321 becomes "987.654.321"
  • 123 becomes "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
Thousand Separator ProblemInput: 12345671234567⬇️ Add dots every 3 digits from right ⬇️Output: "1.234.567"1.234.5671 digit3 digits3 digits
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
Asked in
Google 15 Amazon 12 Microsoft 10
28.0K Views
Medium Frequency
~15 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen