Leetcode Problem 2424. Longest Uploaded Prefix

2424. Longest Uploaded Prefix

Leetcode Solutions

Maintaining a Boolean Array to Track Uploaded Videos

  1. Initialize a boolean array stream of size n with False values.
  2. Set maxLength to n and prefLength to 0.
  3. When upload is called with a video number, set stream[video - 1] to True.
  4. When longest is called, iterate from prefLength to maxLength.
    • If stream[i] is True, increment prefLength.
    • If stream[i] is False, break the loop.
  5. Return prefLength as the length of the longest uploaded prefix.
UML Thumbnail

Using a HashSet to Track Uploaded Videos

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...