r/OfferEngineering • • 2d ago

Coding Question CapitalOne SWE OA Coding Problem - Museum Courier Portal Route

Problem Description

An automated museum courier starts at tile [0, 0] and must reach [row_count - 1, column_count - 1]. The binary matrix floor_plan uses 0 for an open tile and 1 for a blocked tile, and the courier can move only one tile to the right unless a portal transports it elsewhere.

Each record [r1, c1, r2, c2] in portals places an entrance at [r1, c1] with exit [r2, c2]. Whenever the courier occupies an entrance, including at its starting tile, it must immediately take that portal; if the exit is another entrance, it immediately continues along the portal chain before attempting a rightward move.

Count every tile arrival as one step, including the starting tile, each portal entrance, each portal exit, and the destination. An exit that is also the next entrance counts once for that arrival, and reaching the destination ends the route immediately, even if that tile has a portal.

Return the total number of steps when the courier reaches the destination. Return -1 if it cannot move because the next tile is blocked or it is at the right edge without a portal or destination, and return -2 if it revisits any tile and therefore enters an infinite loop.

Constraints:

  • 1 ≤ row_count, column_count ≤ 100,000.
  • floor_plan has exactly row_count rows and column_count columns, and contains only 0 and 1.
  • The starting tile and the destination are open.
  • 0 ≤ portals.length ≤ row_count × column_count.
  • Each portal record contains four integers, with row coordinates in [0, row_count - 1] and column coordinates in [0, column_count - 1].
  • Every entrance is unique, and all portal entrances and exits are on open tiles.
  • Coordinates are zero-indexed. A successful step count can exceed the signed 32-bit integer range.

Want to practice it before interview?

You can practice it and view solution code at here.

Preparing for your next interview?

Chill Interview tracks recent interview experiences and recurring question patterns across top companies at here.

3 Upvotes

0 comments sorted by