You're managing a video streaming platform where videos must be uploaded in a specific sequence. Imagine you have n videos numbered from 1 to n, but they arrive at your server in random order due to network conditions.
Your task is to build a smart system that tracks the longest consecutive prefix of videos that have been successfully uploaded starting from video 1. For example, if videos 1, 2, and 3 are uploaded (regardless of order), your longest prefix is 3. But if videos 1, 3, and 5 are uploaded, your longest prefix is only 1 (since video 2 is missing).
Design the LUPrefix class with these operations:
LUPrefix(int n)- Initialize for a stream of n videosupload(int video)- Mark video as uploadedlongest()- Return length of longest uploaded prefix
This problem tests your ability to efficiently track consecutive sequences and optimize for frequent queries.
Input & Output
Constraints
- 1 โค n โค 105
- 1 โค video โค n
-
All values of
videoare distinct -
At most 2 ร 105 calls will be made to
uploadandlongest -
At least one call will be made to
longest