PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates proficiency in implementing spec-driven algorithms and data structures in Java, covering route reconstruction (directed graph/path assembly and handling uniqueness and continuity constraints) and a versioned multi-level key-value store (time-versioned entries, deletions, and lexicographic scans).

  • hard
  • Luma
  • Coding & Algorithms
  • Software Engineer

Implement Refactoring Assessment Features

Company: Luma

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

You are given an existing Java project for a general refactoring assessment. The project already contains model classes, comments, and unit tests, but several method bodies are missing. Implement the missing functionality without changing public method signatures. The goal is to pass all tests; clarity is useful, but correctness is the priority. Implement the variant assigned to you. ### Variant A: Reconstruct a Simple Route Implement: ```java List<String> buildRoute(List<Ticket> tickets, String start) ``` where each `Ticket` has: ```java String from; String to; ``` Rules: - Each ticket represents a directed trip from `from` to `to`. - Each ticket may be used at most once. - Return the ordered list of locations visited, including the starting location and every destination. - The returned route must start at `start` and use all tickets exactly once. - If `tickets` is empty, return a list containing only `start`. - If the input is invalid, throw `IllegalArgumentException`. Invalid cases include: - `tickets` is `null`. - `start` is `null` or blank. - A ticket is `null`, or its `from`/`to` value is `null` or blank. - Two tickets have the same `from` value, making the next step ambiguous. - The tickets cannot form one continuous route starting from `start` that uses every ticket exactly once. Example: ```text start = "SFO" tickets = [SFO -> LAX, LAX -> JFK, JFK -> BOS] return ["SFO", "LAX", "JFK", "BOS"] ``` ### Variant B: Implement a Versioned Multi-Level Key-Value Store Implement a class with the following public API: ```java class VersionedStore { void set(String recordKey, String fieldKey, String value, int timestamp); String get(String recordKey, String fieldKey, int timestamp); boolean delete(String recordKey, String fieldKey, int timestamp); List<String> scan(String recordKey, int timestamp); List<String> scanByPrefix(String recordKey, String prefix, int timestamp); } ``` The store has two key levels: `recordKey -> fieldKey -> versioned values`. Rules: - `set(recordKey, fieldKey, value, timestamp)` stores `value` for the given record and field at `timestamp`. - `get(recordKey, fieldKey, timestamp)` returns the latest value whose timestamp is less than or equal to the query timestamp. - If the field does not exist at that time, return `null`. - `delete(recordKey, fieldKey, timestamp)` records a deletion at `timestamp`. - Return `true` if the field existed immediately before this deletion timestamp. - Return `false` otherwise. - After deletion, queries at later timestamps should return `null` until the field is set again. - `scan(recordKey, timestamp)` returns all fields that exist in the record at `timestamp`, sorted lexicographically by `fieldKey`. - `scanByPrefix(recordKey, prefix, timestamp)` returns only existing fields whose `fieldKey` starts with `prefix`, also sorted lexicographically. - Scan results should be formatted as: ```text fieldKey(value) ``` Example: ```text set("user1", "name", "Ana", 1) set("user1", "city", "NYC", 2) get("user1", "name", 2) -> "Ana" scan("user1", 2) -> ["city(NYC)", "name(Ana)"] delete("user1", "name", 3) -> true get("user1", "name", 4) -> null set("user1", "name", "Ann", 5) get("user1", "name", 5) -> "Ann" ``` Assume update operation timestamps are positive integers and strictly increase across calls to `set` and `delete`. Query timestamps may be any positive integer.

Quick Answer: This question evaluates proficiency in implementing spec-driven algorithms and data structures in Java, covering route reconstruction (directed graph/path assembly and handling uniqueness and continuity constraints) and a versioned multi-level key-value store (time-versioned entries, deletions, and lexicographic scans).

Part 1: Reconstruct a Simple Route

You are given a starting location and a collection of directed travel tickets. Each ticket has a from location and a to location. Build the ordered route of visited locations, starting from start, using every ticket exactly once. For this function-based version, each ticket is represented as a two-element list or tuple: [from, to]. If the input is invalid, raise ValueError. Invalid cases include null inputs, blank location strings, duplicate from locations, or tickets that cannot form one continuous route from start using all tickets exactly once.

Constraints

  • 0 <= len(tickets) <= 200000
  • start, from, and to values are non-blank strings for valid inputs
  • Each ticket is a pair [from, to]
  • A valid route must use every ticket exactly once
  • No two valid tickets may have the same from value

Examples

Input: ([['SFO', 'LAX'], ['LAX', 'JFK'], ['JFK', 'BOS']], 'SFO')

Expected Output: ['SFO', 'LAX', 'JFK', 'BOS']

Explanation: The tickets already form a direct chain from SFO to BOS.

Input: ([], 'HOME')

Expected Output: ['HOME']

Explanation: With no tickets, the route contains only the starting location.

Input: ([['B', 'C'], ['A', 'B'], ['C', 'D']], 'A')

Expected Output: ['A', 'B', 'C', 'D']

Explanation: Tickets may be provided out of order; the route is reconstructed using the from-to links.

Input: ([['A', 'B'], ['B', 'A']], 'A')

Expected Output: ['A', 'B', 'A']

Explanation: A cycle is valid if all tickets are used exactly once.

Hints

  1. Because duplicate from values are invalid, you can map each from location to exactly one to location.
  2. While walking the route, track which from locations have already been used so you do not reuse a ticket in a cycle before all tickets are consumed.

Part 2: Versioned Multi-Level Key-Value Store

Implement a versioned two-level key-value store with records and fields. A value is stored under recordKey -> fieldKey at a timestamp. Queries should return the latest value whose timestamp is less than or equal to the query timestamp. Deletions create tombstones: after deletion, the field should not exist until it is set again. For this function-based challenge, process a list of operations and return the outputs of read-like operations.

Constraints

  • 0 <= len(operations) <= 200000
  • recordKey, fieldKey, prefix, and value are strings
  • Timestamps in operation input are positive integer strings
  • Timestamps of set and delete operations are strictly increasing in call order
  • Query timestamps may refer to the past, present, or future relative to previously processed updates

Examples

Input: ([['set', 'user1', 'name', 'Ana', '1'], ['set', 'user1', 'city', 'NYC', '2'], ['get', 'user1', 'name', '2'], ['scan', 'user1', '2'], ['delete', 'user1', 'name', '3'], ['get', 'user1', 'name', '4'], ['set', 'user1', 'name', 'Ann', '5'], ['get', 'user1', 'name', '5'], ['scan', 'user1', '5']],)

Expected Output: [['Ana'], ['city(NYC)', 'name(Ana)'], ['true'], [], ['Ann'], ['city(NYC)', 'name(Ann)']]

Explanation: The name field is visible, then deleted, then set again with a new value.

Input: ([] ,)

Expected Output: []

Explanation: No operations produce no results.

Input: ([['delete', 'r', 'a', '1'], ['get', 'r', 'a', '1'], ['set', 'r', 'apple', 'red', '2'], ['set', 'r', 'ape', 'gray', '3'], ['set', 'r', 'banana', 'yellow', '4'], ['scanByPrefix', 'r', 'ap', '4'], ['delete', 'r', 'apple', '5'], ['scanByPrefix', 'r', 'ap', '6']],)

Expected Output: [['false'], [], ['ape(gray)', 'apple(red)'], ['true'], ['ape(gray)']]

Explanation: Deleting a missing field returns false. Prefix scans include only existing matching fields in lexicographic order.

Input: ([['set', 'r', 'f', 'v1', '5'], ['get', 'r', 'f', '4'], ['get', 'r', 'f', '5'], ['set', 'r', 'f', 'v2', '10'], ['delete', 'r', 'f', '15'], ['get', 'r', 'f', '14'], ['get', 'r', 'f', '15'], ['set', 'r', 'f', 'v3', '20'], ['scan', 'r', '12'], ['scan', 'r', '16'], ['get', 'r', 'f', '20']],)

Expected Output: [[], ['v1'], ['true'], ['v2'], [], ['f(v2)'], [], ['v3']]

Explanation: Historical queries use the latest version at or before the requested timestamp, even after later updates have been processed.

Hints

  1. Store a sorted version history for each recordKey and fieldKey. Because update timestamps increase, you can append new versions.
  2. Use binary search to find the latest version whose timestamp is at most the query timestamp.
Last updated: Jun 13, 2026

Related Coding Questions

  • Solve Seven Python Image and Data Tasks - Luma (medium)

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.