Category: String coding problemYou are building a food discovery platform. Given a user's location, a list of restaurants with their coordinates, and a menu of items with prices,...Input: List Output: Computed result
codingMediumVerified Question#2
2. Worker Task Scheduler
Category: String coding problemYou are given a list of tasks sorted by start time. Each task is represented as a three-element list [task_id, start_time, duration], where...Input: List Output: Array
codingMediumVerified Question#3
3. Paged Data Reader
Category: Trie-based coding problemYou have an external data source that serves records in fixed pages. The data source is represented as a list of pages, where each page is a list of...Input: Array of strings Output: Computed result
codingMediumVerified Question#4
4. Multi-Source Reader
Category: String coding problemImplement a MultiSource class that manages a collection of character sources. Each source is a string of characters. You can add and remove sources...Input: String Output: Printed output
codingHardVerified Question#5
5. Transactional Cache
Category: String coding problemImplement an in-memory key-value cache that supports nested transactions. The cache stores string keys mapped to string values and provides the...Input: String Output: Computed result
codingHardVerified Question#6
6. Probe Collision Simulator
Category: Algorithm coding problemA set of probes is arranged in a line from left to right. Each probe has a mass and a velocity. A positive velocity means the probe moves to the...Input: List Output: Computed result
codingMediumVerified Question#7
7. Range Coverage Tracker
Category: Interval-based coding problemYou are painting a road of total length n. Each paint stroke starting at position x covers the segment [x, x + 1]. Implement a RangeTracker...Input: Given input Output: Computed result
codingHardVerified Question#8
8. Log Query Engine
Category: String coding problemYou are given a collection of log records. Each record is a five-element list of strings: [time, id, user, type, value], where time and value...Input: Array of strings Output: Computed result
codingMediumgeometry#1
1. Coding — Find optimal ride-sharing pairs
Background: Lyft connects drivers with riders in real time. While matching these pairs, it is essential to minimize waiting times and maximize ride efficiency. Problem statement: You are given a list of n riders, where each rider has a unique identifier along with their pickup and drop-off locations represented as point coordinates. The goal is to find the optimal k pairs of riders that can share a ride based on the smallest total distance traveled, where the distance is calculated using the Euclidean distance formula. Return a list of pairs of rider IDs. Function/class signature:
2. CODING — Find Missing Driver in a Ride Matching System
Background: Lyft's driver-rider matching service relies on efficient allocation of drivers to riders in real-time. Identifying missing drivers in specific scenarios can help improve system efficiency and rider satisfaction. Problem statement: Given a list of drivers available for matched rides and a list of completed_rides which includes driver identifiers, your task is to find the driver identifiers who are available but not included in the completed_rides. The function should return a list of these missing drivers. Function/class signature:
Background: Lyft needs to efficiently calculate the minimum cost for a rider based on the distance, time, and pricing tiers for rides. As the demand for on-demand transport increases, rideshare companies face the challenge of providing cost-effective estimates for users. Problem statement: You are tasked with implementing a function to compute the minimum ride cost for a rider. The function should take an array of ride options, each with a distance, time, and cost per mile, and return the minimum total cost for a given distance and time. The pricing structure may vary based on the ride type. Function/class signature:
Explanation: The second ride option gives a total cost of 4 * 6 + 5 * 10 = 15.0.
Constraints:
1 <= len(ride_options) <= 100
1 <= distance <= 1000
1 <= duration <= 1000
0 < cost per mile <= 10
codingMediumgraph#4
4. [Graph] — Implement a driver-rider matching algorithm
Background: Lyft operates a real-time service that matches riders with nearby drivers. Efficient matching is crucial for providing quick pickups, optimizing driver routes, and enhancing overall user satisfaction. Problem statement: You need to implement a function that simulates a simplified version of the driver-rider matching process. Given a list of drivers' locations and riders' locations, the function should find the nearest driver for each rider. The distance between two points can be calculated using the Euclidean distance formula. You should return a list of pairs, where each pair consists of a rider and their matched driver. Function/class signature:
Explanation: The rider at (2, 2) can only be matched to the driver at (0, 0) because it's closer.
Constraints:
1 ≤ len(drivers), len(riders) ≤ 10^4
Driver and rider coordinates are within the range of (-10^5, 10^5)
codingMediumgeolocation#5
5. Coding — Driver Rider Matching Algorithm
Background: Lyft needs an efficient way to match riders with drivers based on proximity and availability to ensure a quick and reliable service for users. This problem is crucial as it directly impacts the user experience of the Lyft application.Problem statement: Given a list of drivers with their current locations as (lat, lon) and a list of riders with their pickup locations, implement a function to match each rider with the nearest available driver. You should return a list of pairs indicating which driver has been assigned to each rider. Assume each driver can serve only one rider at a time.Function/class signature:
Explanation: The only available driver serves the first rider, and the second rider remains unmatched.
Constraints:
1 <= len(drivers) <= 100
1 <= len(riders) <= 100
Latitude and Longitude values are in the range of [-90, 90] and [-180, 180] respectively.
codingMediumgreedy#6
6. LeetCode-style coding challenge — Implement a function to find the optimal ride sharing match
Background: Lyft’s core business involves matching drivers to riders efficiently based on various factors like distance, time, and rider preferences. To enhance the customer experience, it’s crucial to develop an algorithm that can quickly find the best match for both parties. Problem statement: Given a list of drivers represented as tuples of (id, location) and a list of riders represented as (id, pickup_location), implement a function to return a list of matches. Each match should be a tuple (rider_id, driver_id) such that the distance between the driver and rider is minimized. Assume you have a helper function calculate_distance(location1, location2) that returns the distance between two locations. Function/class signature:
Explanation: Driver 1 is closest to rider 1, and driver 2 is closest to rider 2.
Example 2:
Input: drivers = [(1, (2, 3))]
riders = [(1, (1, 1)), (2, (3, 3))]
Output: [(1, 1), (2, 1)]
Explanation: Both riders match with driver 1 because there's only one driver available.
Constraints:
1 <= len(drivers) <= 100
1 <= len(riders) <= 100
Location coordinates are floating point values, within the range (-10^6, 10^6)
system designMediumapi design#7
7. Design DriverRiderMatcher — a service for efficiently matching drivers with riders based on real-time demand and supply conditions.
Background: Lyft aims to enhance user experience by ensuring that riders can be matched quickly to nearby drivers. This service would handle the complexities of demand and supply fluctuations in real-time.Requirements: 1. The service should allow adding new Driver and Rider instances dynamically as they request a ride or become available. 2. The system must prioritize matching riders with the nearest available driver to minimize wait times. 3. It should support cancellation of ride requests by riders or drivers, updating the available pool appropriately. 4. The service must track ongoing rides and maintain a history of matches for potential analytics. Class API:
add_driver(driver_id: int, location: Tuple[float, float]) -> None: Adds a new driver to the service with a given ID and location.
add_rider(rider_id: int, location: Tuple[float, float]) -> None: Registers a new rider with a given ID and location.
request_ride(rider_id: int) -> Optional[int]: Matches the rider with the nearest driver, returning the driver's ID or None if no driver is available.
cancel_ride(rider_id: int) -> None: Cancels the ride request for the specified rider, freeing up any matched driver.