Solve Refueling and JSON Parsing Tasks
Company: Geico
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Onsite
Quick Answer: This multipart question evaluates algorithmic problem-solving and parsing competencies, specifically resource-optimization and data-structure use for minimizing refueling stops alongside tokenizer and parse-tree construction, string-escape handling, and type recognition for JSON parsing, and is classified in the Coding & Algorithms domain.
Part 1: Minimize Refueling Stops
Constraints
- 1 <= target <= 10^9
- 0 <= startFuel <= 10^9
- 0 <= len(stations) <= 10^5
- 0 <= position_i < target
- 1 <= fuel_i <= 10^9
- stations is sorted by increasing position
Examples
Input: (100, 10, [[10, 60], [20, 30], [30, 30], [60, 40]])
Expected Output: 2
Explanation: Refuel at position 10 and later at position 60 to reach the target in 2 stops.
Input: (1, 1, [])
Expected Output: 0
Explanation: You already have enough fuel to reach the destination, so no stop is needed.
Input: (100, 1, [[10, 100]])
Expected Output: -1
Explanation: You cannot even reach the first station.
Input: (100, 50, [[25, 25], [50, 50]])
Expected Output: 1
Explanation: Reach position 50, refuel once, and then finish the trip.
Hints
- As you drive, keep track of every station you have already passed and could have used.
- When you run out of reachable distance, refuel from the previously passed station with the largest fuel amount.
Part 2: Implement a JSON String Parser
Constraints
- 1 <= len(s) <= 10^5
- The input string is guaranteed to be valid JSON
- Numbers in the input fit in Python's int or float types
- Whitespace may appear between tokens
- Nesting depth is within Python's recursion limit
Examples
Input: '{"a":[1,true,null],"b":"hello"}'
Expected Output: {'a': [1, True, None], 'b': 'hello'}
Explanation: This tests nested arrays, booleans, null, and object parsing.
Input: ' [ -2, 3.5, 1e2 ] '
Expected Output: [-2, 3.5, 100.0]
Explanation: This tests whitespace handling and number parsing, including decimals and exponents.
Input: 'null'
Expected Output: None
Explanation: A single JSON null should become Python None.
Input: '"line\nfeed"'
Expected Output: 'line\nfeed'
Explanation: The parser should convert the escaped newline into an actual newline character in the returned string.
Input: '{}'
Expected Output: {}
Explanation: An empty object is a useful edge case.
Hints
- Use a shared index pointer and recursive descent: decide what to parse by looking at the current character.
- Strings need special care: when you see a backslash, translate the escape sequence before continuing.