Format a Signed Integer with Commas
Updated
Problem statement
Given a signed integer value, return its base-10 representation with a comma between every group of three digits, counting from the right.
Keep a leading minus sign before all digits. Do not add leading zeros or a plus sign.
Function
formatWithCommas(value: int) → StringExamples
Example 1
value = 1234return = "1,234"Reading from the right, the final three digits form one group, so one comma precedes 234.
Example 2
value = -9876543return = "-9,876,543"The magnitude is split into 9, 876, and 543; the minus sign remains at the front.
Example 3
value = 0return = "0"A one-digit value needs no separator.
Constraints
-2^31 <= value <= 2^31 - 1.- The result contains only decimal digits, comma separators, and an optional leading minus sign.
More Hudson River Trading Phone Screen questions
- Order and Batch Open-Close LifecyclePHONE SCREEN · Seen Nov 2026
- Tilting Maze BallPHONE SCREEN · Seen Oct 2026
- Tiered Expiring Item StorePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Mean vs Median: Chance of Missing the CenterPHONE SCREEN · Seen Sep 2026
- Market Data Signal WatcherPHONE SCREEN · Seen Jul 2026
- Integer to String Without Built-insPHONE SCREEN · Seen May 2026
- Contact Tracing Through Timed MeetingsPHONE SCREEN · Seen Nov 2024
- Polydivisible Pandigital NumbersPHONE SCREEN · Seen Feb 2024
- Defragment a Buffer of ObjectsPHONE SCREEN · Seen Nov 2023
- Expected People Met Before Someone TallerPHONE SCREEN · Seen Nov 2023
Similar questions at other companies
- Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
- Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
- Portfolio Valuation, Part 1Stripe · PHONE SCREENStripe interview questions
- Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
- Run-Length DecodingApple · PHONE SCREENApple interview questions
- Trace Pointer Rebinding and Pointee UpdatesArista Networks · PHONE SCREENArista Networks interview questions
- Match a Variadic Function SignatureConfluent · PHONE SCREENConfluent interview questions
- Decode and Store StringsAirbnb · PHONE SCREENAirbnb interview questions
- Delimiter-Parsing String Iteratoramo · PHONE SCREEN
- SimpleRDD Word CountDatologyAI · PHONE SCREEN