Format an Integer with Thousands Separators

Quick Overview

Format a signed integer with a separator every three digits, including correct handling of negative values.

Format an Integer with Thousands Separators

Company: Hudson

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

# Format an Integer with Thousands Separators Implement `format_with_commas(value: int) -> str`. Return the base-10 representation of `value` with a comma inserted between every group of three digits counted from the right. A negative value keeps exactly one leading minus sign. Do not add leading zeros, and return `"0"` for zero. ## Valid Input Domain - `value` is a signed 64-bit integer. ## Constraints - `-9,223,372,036,854,775,808 <= value <= 9,223,372,036,854,775,807` - The implementation must handle the minimum signed 64-bit value without overflowing while taking an absolute value. ## Public Examples ### Example 1 Input: `1234` Output: `"1,234"` ### Example 2 Input: `-9876543` Output: `"-9,876,543"` ```hint Work from the right edge The sign is separate from the repeated three-digit grouping rule. ```

Overview: Format a signed integer with a separator every three digits, including correct handling of negative values.

|Home/Coding & Algorithms/Hudson
Hudson logo
Hudson
Aug 30, 2026
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
1
0

Format an Integer with Thousands Separators

Implement format_with_commas(value: int) -> str.

Return the base-10 representation of value with a comma inserted between every group of three digits counted from the right. A negative value keeps exactly one leading minus sign. Do not add leading zeros, and return "0" for zero.

Valid Input Domain

  • value is a signed 64-bit integer.

Constraints

  • -9,223,372,036,854,775,808 <= value <= 9,223,372,036,854,775,807
  • The implementation must handle the minimum signed 64-bit value without overflowing while taking an absolute value.

Public Examples

Example 1

Input: 1234

Output: "1,234"

Example 2

Input: -9876543

Output: "-9,876,543"

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...