Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Convert Strings to Numbers

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Convert Strings to Numbers. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Caesars Sportsbook receives wager amount fields as strings. Convert each string to a base-10 integer while preserving input order and handling malformed or out-of-range values safely.

Implement convert_number_strings(values, min_value, max_value). Trim surrounding whitespace, accept an optional leading + or -, and require at least one ASCII digit after the sign. Valid values within the inclusive range [min_value, max_value] become integers. Return None for empty strings, sign-only strings, strings containing non-digit characters, or values outside the range.

Do not use Python's int() conversion for the main solution. The input list itself must not be modified.

Formal Specification

  • Input: values, a list of strings; min_value and max_value, integers where min_value <= max_value.
  • Output: A list containing either the parsed integer or None for each input string.
  • Whitespace is allowed only around the number, not between its sign and digits or between digits.

Constraints

  • 0 <= len(values) <= 10^4
  • 0 <= len(values[i]) <= 32
  • -10^9 <= min_value <= max_value <= 10^9
  • Only ASCII digits may appear after an optional leading sign
  • The input list must not be modified

Function Signature

def convert_number_strings(values, min_value, max_value):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output