PracHub
QuestionsPremiumLearningGuidesInterview PrepCoaches

Quick Overview

This multi-part question evaluates skills in graph traversal and shortest-path reasoning (minimum transit routes), precise string and numeric manipulation with carry handling (rounding), financial accounting and minimization of transactions (shared expenses), and scheduling with ordered data structures and nearest-neighbor selection (dynamic elevator assignment). Commonly asked in the Coding & Algorithms domain to assess algorithmic reasoning, robust edge-case handling, data-structure selection, and time/space complexity analysis, it combines conceptual understanding of algorithms with practical implementation concerns for efficient, correct solutions.

  • medium
  • Pinterest
  • Coding & Algorithms
  • Software Engineer

Solve Multiple Coding Interview Problems

Company: Pinterest

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

The interview included the following independent coding tasks. Solve each task, explain edge cases, and analyze time and space complexity. 1. Minimum transit routes: You are given an array of transit lines, where each line is a list of stops served in a repeating cycle. You are also given a source stop and a target stop. You may board any line that serves your current stop and transfer between lines at shared stops. Return the minimum number of lines you must take to get from source to target, or -1 if it is impossible. 2. Round by the least significant digit: You are given a string representing a non-negative integer or decimal number, with no sign and at most one decimal point. Round the number by looking at its least significant digit. If that digit is 5 or greater, carry one unit into the previous digit position; otherwise, round down. Preserve one fewer digit of precision. For example, 1234 becomes 1230, 1295 becomes 1300, 1.234 becomes 1.23, 1.235 becomes 1.24, 1.99 becomes 2.0, and 9 becomes 10. Handle carries across decimal points and across all integer digits. 3. Simplify shared expenses: You are given users and a list of expenses. Each expense contains a payer, an amount in cents, and either an equal split among participants or explicit participant shares. Compute each user's net balance and return a list of settlement payments that clears all balances while using as few payments as possible. 4. Dynamic elevator assignment: You are given n elevators, each with an id and an initial floor at time 0. You are also given requests of the form timestamp and pickup_floor. Each elevator moves at one floor per second toward its last assigned target and stays there after arrival. For each request in chronological order, compute every elevator's current floor at that timestamp, choose the elevator closest to the pickup floor, breaking ties by smaller id, assign that elevator's new target to the pickup floor, and output the chosen elevator id. Discuss how to maintain the nearest elevator efficiently with an ordered data structure.

Quick Answer: This multi-part question evaluates skills in graph traversal and shortest-path reasoning (minimum transit routes), precise string and numeric manipulation with carry handling (rounding), financial accounting and minimization of transactions (shared expenses), and scheduling with ordered data structures and nearest-neighbor selection (dynamic elevator assignment). Commonly asked in the Coding & Algorithms domain to assess algorithmic reasoning, robust edge-case handling, data-structure selection, and time/space complexity analysis, it combines conceptual understanding of algorithms with practical implementation concerns for efficient, correct solutions.

Part 1: Minimum Transit Routes

You are given transit lines, where each line is a list of stops served by that line in a repeating cycle. If you board a line, you may ride it to any stop on that same line. You may transfer between lines at shared stops. Given a source stop and a target stop, return the minimum number of lines you must take to travel from source to target. Return -1 if the trip is impossible.

Constraints

  • 0 <= len(lines) <= 10000
  • 1 <= total number of stop entries across all lines <= 100000
  • Stops are integers
  • If source == target, the answer is 0

Examples

Input: ([[1, 2, 7], [3, 6, 7]], 1, 6)

Expected Output: 2

Explanation: Take line 0 from stop 1 to stop 7, then transfer to line 1 to reach stop 6.

Input: ([[1, 5, 7], [3, 6, 9]], 1, 6)

Expected Output: -1

Explanation: The two lines do not share a stop, so the destination cannot be reached.

Input: ([[1, 2, 3]], 2, 2)

Expected Output: 0

Explanation: Source and target are the same stop, so no line is needed.

Input: ([], 1, 2)

Expected Output: -1

Explanation: There are no transit lines at all.

Hints

  1. Build a mapping from each stop to all line indices that contain that stop.
  2. Run BFS by line count: boarding a new line increases the answer by 1.

Part 2: Round by the Least Significant Digit

You are given a string representing a non-negative integer or decimal number. Round the number by inspecting its least significant digit, then remove that digit from the final representation. If the least significant digit is 5 or greater, carry 1 into the previous digit position; otherwise round down. The result must preserve one fewer digit of precision. Handle carries across decimal points and across all integer digits. Return the result as a canonical string with no unnecessary leading zeros, and include a decimal point only when at least one fractional digit remains.

Constraints

  • 1 <= len(num) <= 100000
  • num contains only digits and at most one decimal point
  • num has no sign
  • There is at least one digit in the input

Examples

Input: ('1295',)

Expected Output: '1300'

Explanation: The last digit is 5, so carry into the tens place: 1295 becomes 1300.

Input: ('1.235',)

Expected Output: '1.24'

Explanation: The last digit is 5, so the hundredths digit increases from 3 to 4.

Input: ('1.99',)

Expected Output: '2.0'

Explanation: The last digit is 9, so carrying crosses the decimal boundary.

Input: ('9',)

Expected Output: '10'

Explanation: A carry across all integer digits creates a new leading digit.

Input: ('0.04',)

Expected Output: '0.0'

Explanation: The last digit is 4, so it rounds down while keeping one fewer fractional digit.

Hints

  1. Temporarily remove the decimal point and treat the number like a digit string.
  2. After processing the carry, put the decimal point back so the result has one fewer fractional digit than before.

Part 3: Simplify Shared Expenses

Users are identified by integers from 0 to n - 1. You are given a list of expenses. Each expense records a payer, an amount in cents, and either an equal split among participants or exact participant shares. First compute each user's final net balance: positive means the user should receive money, negative means the user owes money. Then return a list of settlement payments that clears all balances using the minimum possible number of payments. If multiple optimal settlement lists exist, return the lexicographically smallest one after sorting payments by from_user, then to_user, then amount.

Constraints

  • 1 <= n <= 8
  • 0 <= len(expenses) <= 50
  • All amounts and shares are non-negative integers in cents
  • For equal splits, amount is divisible by the number of participants
  • For exact splits, the provided shares sum exactly to amount
  • The exact optimization is intended for small n

Examples

Input: (3, [[0, 3000, 0, 3, 0, 1, 2]])

Expected Output: [[1, 0, 1000], [2, 0, 1000]]

Explanation: User 0 paid for all three users equally, so users 1 and 2 each owe user 0 one share.

Input: (4, [[0, 2000, 0, 2, 0, 1], [2, 2000, 0, 2, 2, 3]])

Expected Output: [[1, 0, 1000], [3, 2, 1000]]

Explanation: The two expenses are independent, so one payment settles each pair.

Input: (4, [[0, 4000, 0, 4, 0, 1, 2, 3], [2, 1000, 1, 2, 0, 2, 200, 800]])

Expected Output: [[1, 0, 1000], [2, 0, 800], [3, 0, 1000]]

Explanation: After combining both expenses, user 0 should receive 2800 cents and users 1, 2, and 3 owe 1000, 800, and 1000 cents.

Input: (1, [[0, 500, 0, 1, 0]])

Expected Output: []

Explanation: The only user paid only for themselves, so the net balance is already zero.

Input: (3, [])

Expected Output: []

Explanation: No expenses means no balances to settle.

Hints

  1. First compress all expenses into one net balance per user.
  2. After that, the problem becomes an exact minimum-transaction settlement search over a small state space.

Part 4: Dynamic Elevator Assignment

You manage multiple elevators. Each elevator has a unique id and an initial floor at time 0. Requests arrive in chronological order, each containing a timestamp and a pickup floor. Every elevator moves at one floor per second toward its current target and then stays there after arrival. For each request, first compute every elevator's current floor at that timestamp, then choose the elevator closest to the pickup floor, breaking ties by smaller id. Assign that elevator a new target equal to the pickup floor and output its id. If multiple requests have the same timestamp, process them in the given order. A straightforward simulation is acceptable here; as an extension, you can discuss how an ordered structure keyed by current floors could help nearest-elevator queries after updates.

Constraints

  • 1 <= len(elevators) <= 2000
  • 0 <= len(requests) <= 2000
  • Elevator ids are unique integers
  • Timestamps are non-decreasing
  • Floors are integers

Examples

Input: ([[1, 0], [2, 10]], [[0, 2], [3, 9], [5, 1]])

Expected Output: [1, 2, 1]

Explanation: Elevator 1 handles the first and third requests, and elevator 2 is closer to the second.

Input: ([[1, 0], [2, 4]], [[1, 3], [1, 1]])

Expected Output: [2, 1]

Explanation: The second request happens at the same timestamp, so the previously chosen elevator has not moved yet.

Input: ([[5, 2], [3, 4]], [[0, 3]])

Expected Output: [3]

Explanation: Both elevators are equally close to floor 3, so the smaller id wins.

Input: ([[7, 0]], [[0, 10], [3, 2], [5, 5]])

Expected Output: [7, 7, 7]

Explanation: The single elevator is reassigned while moving; each new target starts from its current floor at that time.

Hints

  1. Store each elevator's current floor, current target, and last update time; update lazily when a request arrives.
  2. After all elevators are updated to the request time, choose the one minimizing distance to pickup, then id.
Last updated: May 30, 2026

Loading coding console...

PracHub

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

Related Coding Questions

  • Implement a Sparse Matrix Class - Pinterest (medium)
  • Assign Pins to Shortest Columns - Pinterest (medium)
  • Design Hierarchical Permission Checks - Pinterest (medium)
  • Implement weighted random choice - Pinterest (medium)
  • Solve five hard algorithm problems - Pinterest