Leetcode #2254: Design Video Sharing Platform
In this guide, we solve Leetcode #2254 Design Video Sharing Platform in Python and focus on the core idea that makes the solution efficient.
You will see the intuition, the step-by-step method, and a clean Python implementation you can use in interviews.

Problem Statement
You have a video sharing platform where users can upload and delete videos. Each video is a string of digits, where the ith digit of the string represents the content of the video at minute i.
Quick Facts
- Difficulty: Hard
- Premium: Yes
- Tags: Stack, Design, Hash Table, Ordered Set
Intuition
Fast membership checks and value lookups are the heart of this problem, which makes a hash map the natural choice.
By storing what we have already seen (or counts/indexes), we can answer the question in one pass without backtracking.
Approach
Scan the input once, using the map to detect when the condition is satisfied and to update state as you go.
This keeps the solution linear while remaining easy to explain in an interview setting.
Steps:
- Initialize a hash map for seen items or counts.
- Iterate through the input, querying/updating the map.
- Return the first valid result or the final computed value.
Example
Input
["VideoSharingPlatform", "upload", "upload", "remove", "remove", "upload", "watch", "watch", "like", "dislike", "dislike", "getLikesAndDislikes", "getViews"]
[[], ["123"], ["456"], [4], [0], ["789"], [1, 0, 5], [1, 0, 1], [1], [1], [1], [1], [1]]
Output
[null, 0, 1, null, null, 0, "456", "45", null, null, null, [1, 2], 2]
Explanation
VideoSharingPlatform videoSharingPlatform = new VideoSharingPlatform();
videoSharingPlatform.upload("123"); // The smallest available videoId is 0, so return 0.
videoSharingPlatform.upload("456"); // The smallest available videoId is 1, so return 1.
videoSharingPlatform.remove(4); // There is no video associated with videoId 4, so do nothing.
videoSharingPlatform.remove(0); // Remove the video associated with videoId 0.
videoSharingPlatform.upload("789"); // Since the video associated with videoId 0 was deleted,
// 0 is the smallest available videoId, so return 0.
videoSharingPlatform.watch(1, 0, 5); // The video associated with videoId 1 is "456".
// The video from minute 0 to min(5, 3 - 1) = 2 is "456", so return "456".
videoSharingPlatform.watch(1, 0, 1); // The video associated with videoId 1 is "456".
// The video from minute 0 to min(1, 3 - 1) = 1 is "45", so return "45".
videoSharingPlatform.like(1); // Increase the number of likes on the video associated with videoId 1.
videoSharingPlatform.dislike(1); // Increase the number of dislikes on the video associated with videoId 1.
videoSharingPlatform.dislike(1); // Increase the number of dislikes on the video associated with videoId 1.
videoSharingPlatform.getLikesAndDislikes(1); // There is 1 like and 2 dislikes on the video associated with videoId 1, so return [1, 2].
videoSharingPlatform.getViews(1); // The video associated with videoId 1 has 2 views, so return 2.
Python Solution
Complexity
The time complexity is O(n). The space complexity is O(n).
Edge Cases and Pitfalls
Watch for boundary values, empty inputs, and duplicate values where applicable. If the problem involves ordering or constraints, confirm the invariant is preserved at every step.
Summary
This Python solution focuses on the essential structure of the problem and keeps the implementation interview-friendly while meeting the constraints.