Skip to main content

Build Route

MIDDLE

Build Route

Given an array of route segments, build the complete route path.

Requirements:

  • Each segment has from/to properties
  • Build complete route from start to end
  • Handle disconnected segments

Example:

Input: [
  { from: 'A', to: 'B' },
  { from: 'B', to: 'C' },
  { from: 'C', to: 'D' }
]
Output: ['A', 'B', 'C', 'D']

Examples:

Input 1:{"segments":[{"from":"A","to":"B"},{"from":"B","to":"C"},{"from":"C","to":"D"}]}
Output 1:["A","B","C","D"]

Loading editor...

Run your code to see results

Click the Run button above