FastPrepTraveling the Graphs
Problems/Traveling the Graphs

Traveling the Graphs

Optiver logoOptiver● HardFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Optiver online assessment. The parser grammar, the error priorities, the shortest-route rules, and the examples match the report at about 98%. We added a limit on the numbers, and we treat an edge from a node to itself as a logic error.

Parse an undirected weighted graph and one route request.

  • edgeLine contains one or more edge tokens [A,B,5], separated by exactly one space.
  • routeLine has the form A->D,10: start node, destination node, and maximum allowed travel time.
  • Node names are single uppercase letters, and weights and the limit are unsigned decimal integers.

Return the unique shortest route as uppercase node names joined by -> when its total distance is at most the limit.

Otherwise return the first applicable error by priority:

  1. E1: input syntax error.
  2. E2: logical input error: a duplicate undirected edge, a self-edge, an undefined endpoint, a disconnected graph, or more than one shortest route.
  3. E3: the unique shortest route exceeds the allowed travel time.

Function

travelingTheGraphs(edgeLine: String, routeLine: String) → String

Examples

Example 1

edgeLine = "[A,B,3] [B,C,5] [C,D,2]"routeLine = "A->D,10"return = "A->B->C->D"

The only route from A to D has total distance 10, exactly the limit.

Example 2

edgeLine = "[A,B,3] [A,C,7] [C,D,2] [B,C,5]"routeLine = "A->D,10"return = "A->C->D"

A->C->D has distance 9, shorter than the alternative through B.

Example 3

edgeLine = "[A,B,5] [A,C,2] [B,C,4] [B,D,6] [C,B,7]"routeLine = "A->C,10"return = "E2"

[C,B,7] duplicates the already defined undirected edge [B,C,4].

Constraints

  • Every node is one of A through Z.
  • 0 <= edgeWeight, maximumTravelTime <= 10^9
  • The edge line contains at most 325 tokens.
  • No leading, trailing, or repeated whitespace is valid.

More Optiver Online Assessment questions

  • Overheat Prevention ControllerOA · Seen Nov 2026
  • Power Cell BankOA · Seen Nov 2026
  • Count Straight-Line Word Occurrences in a GridOA · Seen Sep 2026
  • Fastest Average Speed over a Rolling KilometerOA · Seen Sep 2026
  • Multi-Level Inventory Storage SystemOA · PHONE SCREEN · Seen Aug 2026
  • Proportional Momentum Investment StatisticsOA · Seen Aug 2026
  • Count Bounded Share TransactionsOA · Seen Aug 2026
  • Count Ordered Size SequencesOA · Seen Aug 2026
  • Profitable Currency Exchange CycleOA · Seen Aug 2026
  • Construct Binary Tree S-ExpressionOA · Seen Jul 2026

Similar questions at other companies

  • Sum Dynamic Weighted Tree DistancesJuspay · OA
  • Evolving Merchant Clusters and Persistent PinsStripe · OAStripe interview questions
  • Spreadsheet With Dependent CellsCharacter.AI · PHONE SCREEN
  • Spreadsheet Formula DependenciesAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Spreadsheet Formula EvaluatorPika · PHONE SCREEN
  • Resolve Variable Equations with Dependency ErrorsApplied Intuition · PHONE SCREENApplied Intuition interview questions
  • Resolve Variable Equations with Dependency ErrorsMotive · PHONE SCREENMotive interview questions
  • Minimum Leaf Path Sum over All RootsInfosys · OAInfosys interview questions
  • Job Runner Chain ReportsHeadlands Technologies · OAHeadlands Technologies interview questions
  • Minimum Fuel Cost Between CitiesMicrosoft · OAMicrosoft interview questions

Optiver interview experiences

  • Optiver SWE Intern OA: CPU Temperature Simulation: 1 Experience
  • Optiver Trading Intern Market-Making Games: 1 Experience
  • Optiver Quant Trader Intern Technical Interview: 1 Experience
  • Optiver SWE Intern System Design Interview: 15 Experiences
All Optiver interview questionsSee Optiver hiring insights
Saved
class Solution {
    public String travelingTheGraphs(String edgeLine, String routeLine) {
      // write your code here
    }
}
Checking account…