PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

The first problem evaluates algorithmic reasoning about ordering constraints and subsequence selection, testing skills in sequence algorithms, multidimensional comparison (geographic coordinates combined with lexicographic ordering) within the coding and algorithms domain; it is commonly asked to gauge the ability to model ordering constraints and implement efficient algorithmic solutions, emphasizing practical implementation over purely conceptual theory. The second problem evaluates string parsing and tokenization competencies, including handling quoted fields, delimiter rules, and preservation or removal of quote characters within the parsing/data-processing domain; it is commonly asked to assess robustness handling of input-format edge cases and focuses on practical parsing implementation.

  • medium
  • Upstart
  • Coding & Algorithms
  • Software Engineer

Find Maximum Eastbound City Visits and Parse CSV

Company: Upstart

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

Answer both coding questions. ### Question 1: Maximum eastbound city visits You are given two arrays of the same length: - `cities[i]`: the name of the `i`-th city. - `x[i]`: the east-west coordinate of the `i`-th city, where a larger value means the city is farther east. A traveler may start at any city. On each move, the traveler may go only to a city that is strictly farther east, and the destination city's name must also be strictly greater in lexicographical order than the current city's name. Return the maximum number of cities the traveler can visit. Example: ```text cities = ["Tucson", "Albany", "Smith", "Westford", "Berkeley"] x = [182, 93, 114, 1421, 50] ``` One valid route is: ```text Albany -> Smith -> Tucson -> Westford ``` So the expected output is: ```text 4 ``` ### Question 2: Parse a comma-separated string with quotes Implement a parser for a comma-separated string. The delimiter is a comma, but commas inside quoted fields should not split the field. Quoted fields may use single quotes or double quotes, and quotes used as field delimiters should be removed from the output. Other quote characters inside a quoted field should be preserved. Example: ```text input = "Hello,'Hi \"to\" you'" output = ["Hello", "Hi \"to\" you"] ``` Return the parsed list of fields.

Quick Answer: The first problem evaluates algorithmic reasoning about ordering constraints and subsequence selection, testing skills in sequence algorithms, multidimensional comparison (geographic coordinates combined with lexicographic ordering) within the coding and algorithms domain; it is commonly asked to gauge the ability to model ordering constraints and implement efficient algorithmic solutions, emphasizing practical implementation over purely conceptual theory. The second problem evaluates string parsing and tokenization competencies, including handling quoted fields, delimiter rules, and preservation or removal of quote characters within the parsing/data-processing domain; it is commonly asked to assess robustness handling of input-format edge cases and focuses on practical parsing implementation.

Part 1: Maximum Eastbound City Visits

You are given two arrays of the same length: `cities`, where `cities[i]` is the name of the i-th city, and `x`, where `x[i]` is its east-west coordinate. A traveler may start at any city. Each next city in the route must be strictly farther east, meaning it has a larger coordinate, and must also have a strictly lexicographically larger city name. Return the maximum number of cities that can be visited in one valid route. If there are no cities, return 0.

Constraints

  • 0 <= len(cities) == len(x) <= 100000
  • City names are non-empty strings when present.
  • The total length of all city names is at most 1000000.
  • -10^9 <= x[i] <= 10^9
  • Duplicate city names and duplicate coordinates may appear; both the coordinate and name comparisons are strict.

Examples

Input: (["Tucson", "Albany", "Smith", "Westford", "Berkeley"], [182, 93, 114, 1421, 50])

Expected Output: 4

Explanation: One optimal route is Albany -> Smith -> Tucson -> Westford.

Input: ([], [])

Expected Output: 0

Explanation: There are no cities to visit.

Input: (["Only"], [10])

Expected Output: 1

Explanation: A single city can always be visited.

Input: (["A", "B", "C"], [1, 1, 2])

Expected Output: 2

Explanation: A and B cannot both be used in order because their coordinates are equal. The best route has length 2, such as A -> C.

Input: (["C", "B", "A"], [1, 2, 3])

Expected Output: 1

Explanation: Although coordinates increase, city names decrease, so no two-city route is valid.

Input: (["A", "A", "B", "C"], [1, 2, 3, 4])

Expected Output: 3

Explanation: The traveler cannot move from A to A because names must be strictly greater. One best route is A -> B -> C.

Hints

  1. Think of each city as a point with two ordered properties: coordinate and lexicographic name.
  2. After sorting by coordinate, use a data structure to quickly find the best previous route ending with a smaller city name. Be careful not to chain cities with the same coordinate.

Part 2: Parse a Comma-Separated String with Quotes

Implement a parser for a comma-separated string. A comma normally separates fields, but commas inside a quoted section do not split the field. Quoted sections may be delimited by either single quotes or double quotes. The quote characters used as delimiters are removed from the returned fields. If a field is quoted with one quote type, the other quote type inside that field is preserved as normal text. Whitespace is significant and should not be trimmed. For this problem, the input is valid: quoted sections are balanced, and there are no escaped matching quote characters inside a quoted section. An empty input string returns an empty list.

Constraints

  • 0 <= len(s) <= 100000
  • The input string contains ordinary characters, commas, single quotes, and double quotes.
  • Quoted sections are balanced and valid.
  • There are no escape sequences; a matching quote ends the current quoted section.
  • Empty fields are allowed, including consecutive commas and a trailing comma.

Examples

Input: ("Hello,'Hi \"to\" you'",)

Expected Output: ["Hello", "Hi \"to\" you"]

Explanation: The comma after Hello splits the fields, but the double quotes inside the single-quoted field are preserved.

Input: ("a,\"b,c\",d",)

Expected Output: ["a", "b,c", "d"]

Explanation: The comma inside the double-quoted field does not split the field.

Input: ("'x,y',\"z's\",plain",)

Expected Output: ["x,y", "z's", "plain"]

Explanation: Single quotes delimit the first field, double quotes delimit the second field, and the apostrophe inside the double-quoted field is preserved.

Input: ("",)

Expected Output: []

Explanation: By definition for this problem, an empty input string represents no fields.

Input: ("one,,\"\",'a,b',tail,",)

Expected Output: ["one", "", "", "a,b", "tail", ""]

Explanation: The parser preserves empty fields, handles an empty quoted field, keeps the comma inside the single-quoted field, and returns an empty final field after the trailing comma.

Hints

  1. Scan the string from left to right while tracking whether you are currently inside a quoted section.
  2. A comma splits the current field only when you are not inside quotes.
Last updated: Jun 13, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ 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.

Related Coding Questions

  • Implement Byte Formatting and Cafeteria Billing - Upstart (medium)
  • Implement Three Assessment Functions - Upstart (medium)
  • Solve Five OA Coding Tasks - Upstart (medium)
  • Solve Reported OA Coding Problems - Upstart (medium)
  • Decode an anagram sentence using vocabulary constraints - Upstart (medium)