Practice Longest Uploaded Prefix
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Longest Uploaded Prefix
Problem Statement
LUPrefix(n) tracks video IDs from 1 through n. upload(video) marks an ID uploaded. longest() returns the largest i such that every ID from 1 through i is uploaded, or zero if ID 1 is missing. Upload IDs are distinct. Practice approach: Store a boolean presence array and a prefix pointer. After an upload, move the pointer while its next ID is present. Each pointer position is visited once, so total advancement is O(n) and longest is O(1). The largest uploaded ID alone is not the prefix length.
Source: Longest Uploaded Prefix on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
["LUPrefix","upload","longest","upload","longest","upload","longest"] [[3],[2],[],[3],[],[1],[]]
[null,null,0,null,0,null,3]
IDs 2 and 3 do not form a prefix until ID 1 arrives.
Constraints
Related LeetCode Problems
Practice more problems similar to Longest Uploaded Prefix.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.