PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • hard
  • Geico
  • Coding & Algorithms
  • Software Engineer

Solve Refueling and JSON Parsing Tasks

Company: Geico

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

Solve the following two independent coding tasks. ### Task 1: Minimize refueling stops You are driving from position `0` to a destination at distance `target`. You start with `startFuel` liters of fuel, and the car consumes exactly `1` liter per mile. Along the route there are gas stations represented as `stations[i] = [position_i, fuel_i]`, sorted by increasing position. If you reach a station, you may choose to refuel there and take all `fuel_i` liters. The fuel tank has unlimited capacity. Return the minimum number of refueling stops needed to reach the destination. If it is impossible, return `-1`. Example: ```text target = 100 startFuel = 10 stations = [[10,60],[20,30],[30,30],[60,40]] Output: 2 ``` ### Task 2: Implement a JSON string parser Implement a function `parseJson(s)` that converts a valid JSON string into the corresponding in-memory value in your programming language. Requirements: - Do not use built-in JSON parsing functions, `eval`, or parser libraries. - Support objects with string keys, arrays, strings, numbers, booleans, and `null`. - Ignore valid whitespace between tokens. - Support common string escape sequences such as `\"`, `\\`, `\/`, `\n`, `\r`, `\t`, `\b`, and `\f`. - You may assume the input string is valid JSON. Example: ```text Input: "{\"a\":[1,true,null],\"b\":\"hello\"}" Output: an object equivalent to {"a":[1,true,null],"b":"hello"} ```

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

You need to travel from position 0 to a destination at distance target. You start with startFuel liters of fuel, and the car uses exactly 1 liter per mile. Gas stations are given as stations[i] = [position_i, fuel_i] in increasing order of position. If you can reach a station, you may stop there and take all of its fuel. Return the minimum number of refueling stops needed to reach the destination, or -1 if the destination cannot be reached.

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

  1. As you drive, keep track of every station you have already passed and could have used.
  2. 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

Write a function that parses a valid JSON string and returns the corresponding in-memory Python value. Support objects with string keys, arrays, strings, numbers, booleans, and null. Ignore valid whitespace between tokens. Support common string escapes including \", \\, \/, \n, \r, \t, \b, \f, and unicode escapes of the form \uXXXX. Do not use built-in JSON parsers, eval, or parser libraries.

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

  1. Use a shared index pointer and recursive descent: decide what to parse by looking at the current character.
  2. Strings need special care: when you see a backslash, translate the escape sequence before continuing.
Last updated: Jun 6, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.