FastPrepFormat a Signed Integer with Commas
Problems/Format a Signed Integer with Commas

Format a Signed Integer with Commas

Hudson River Trading logoHudson River Trading● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The original report provides the formatting rule, a representative example, and explicit negative-number support. A conventional 32-bit integer interface is used for practice.

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) → String

Examples

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

Hudson River Trading interview experiences

  • Hudson River Trading Data Science Interviews: 2 Experiences
  • Hudson River Trading interviews · 2021
  • Hudson River Trading OA · 2021
  • Hudson River Trading interviews · 2022
  • Hudson River Trading OA · 2022
  • Hudson River Trading interviews · 2023
All Hudson River Trading interview questionsSee Hudson River Trading hiring insights
Saved
class Solution {
    public String formatWithCommas(int value) {
      // write your code here
    }
}
Checking account…