← Upstart Interview Insights

Upstart·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Upstart software engineer screen with one coding problem. Pretty short session, maybe 10-15 minutes total, and the problem was straightforward enough that I didn't feel too stressed going in.

Questions Asked (1)

Q1

Write a function that takes an integer number of bytes and returns a formatted string showing the value in the appropriate unit (B, KB, or MB) with two decimal places. 1 KB = 1024 B, 1 MB = 1024 KB.

Algorithms & Data Structures
Author's notes

I got tripped up for a second on the boundary conditions.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the input constraints (e.g., non-negative integer, maximum value) and the expected output format (e.g., '1.50 KB'). Then implement a function that determines the appropriate unit by comparing the byte count against 1024 and 1024^2, divides accordingly, and formats the result to two decimal places. Test with boundary values like 0, 1023, 1024, and 1048576 to ensure correctness.

Pro tip: Mention that using integer arithmetic for the division and then formatting avoids floating-point precision issues, and explicitly state how you handle rounding (e.g., standard rounding). Also, consider edge cases like 0 bytes and values exactly at unit boundaries.

1. Clarify requirements and constraints

Ask about input range (e.g., can it be negative? maximum value?), output format (e.g., '1.50 KB' vs '1.5 KB'), and rounding behavior. Confirm that 1 KB = 1024 B and 1 MB = 1024 KB.

2. Design the unit selection logic

Use conditional checks: if bytes < 1024, unit is B; else if bytes < 1024*1024, unit is KB; else unit is MB. Alternatively, use a loop or logarithm to generalize, but for three units, conditionals are clear.

3. Perform the conversion and formatting

Divide the byte count by the appropriate factor (1 for B, 1024 for KB, 1048576 for MB). Format the result to two decimal places using a method that ensures correct rounding (e.g., sprintf with '%.2f' or equivalent).

4. Handle edge cases and test

Test with 0, 1023, 1024, 1048575, 1048576, and large values. Ensure that 0 returns '0.00 B' and that values just below a unit boundary do not incorrectly round up to the next unit.

5. Discuss potential improvements

Mention extensibility to GB/TB, internationalization, or using a library for formatting. Also, note that the function could be made more efficient or generic with a loop over unit prefixes.

Key Points to Mention

  • Unit thresholds: 1 KB = 1024 B, 1 MB = 1024 KB (binary prefixes).
  • Conditional logic to select the correct unit based on byte count.
  • Division by the appropriate factor (1, 1024, or 1048576) to get the value in the chosen unit.
  • Formatting to two decimal places, including rounding behavior.
  • Edge cases: 0 bytes, values exactly at boundaries (1024, 1048576), and large numbers.
  • Potential floating-point precision issues and how to mitigate them (e.g., using integer arithmetic for division then formatting).

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.