BackmediumBasic Data Structures basic-data-structures medium

Validated Vehicle Exit Sequence Solution

Problem Statement

Given a list of requests where each request is a tuple containing the vehicle's ID and the type of request, either 'entry' or 'exit', determine the order in which the vehicles will exit based on the given list of requests, ensuring a vehicle can only exit if it has previously entered and all vehicles exit in the order they entered.

Example 1
Input
[[1, 'entry'], [2, 'entry'], [1, 'exit'], [2, 'exit']]
Output
[1, 2]

Explanation: The vehicles exit in the order they entered.

Constraints

  • 1 <= number of requests <= 10^5
  • 1 <= vehicle ID <= 10^5
  • Each request is either 'entry' or 'exit'.
  • A vehicle can only exit if it has previously entered.
  • All vehicles exit in the order they entered.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free