676. Design Video Sharing Platform

You need to design a video sharing platform.

Each video is represented by a string of digits. The character at index i shows the content at minute i of the video. The platform must support uploading videos, deleting videos, watching part of a video, liking/disliking a video, and checking its total views, likes, and dislikes.

When a video is uploaded, assign it the smallest available non-negative integer videoId starting from 0. If a video is deleted, its videoId becomes available again and can be reused later.

Implement the VideoSharingPlatform class:

  • VideoSharingPlatform() : Initializes the platform.
  • int upload(String video) : Uploads a video and returns the assigned videoId.
  • void remove(int videoId) : Deletes the video with this videoId if it exists.
  • String watch(int videoId, int startMinute, int endMinute) : If the video exists, increase its views by 1 and return the substring from startMinute to min(endMinute, video.length - 1) inclusive. If the video does not exist, return "-1".
  • void like(int videoId) : Adds 1 like to the video if it exists.
  • void dislike(int videoId) : Adds 1 dislike to the video if it exists.
  • int[] getLikesAndDislikes(int videoId) : Returns [likes, dislikes] if the video exists. Otherwise, return [-1].
  • int getViews(int videoId) : Returns the total views of the video if it exists. Otherwise, return -1.

Notes:

  • Always assign the smallest available videoId
  • Deleted video IDs can be reused
  • watch increases views only if the video exists
  • like, dislike, and remove do nothing if the video does not exist
  • watch returns "-1" if the video does not exist
  • getLikesAndDislikes returns [-1] if the video does not exist
  • getViews returns -1 if the video does not exist

Example 1:

Input:

calls = ["VideoSharingPlatform", "upload", "upload", "watch", "like", "getLikesAndDislikes", "getViews"]

params = [[], ["90876"], ["1234"], [0, 1, 3], [0], [0], [0]]

Output: [null, 0, 1, "087", null, [1, 0], 1]

Explanation:

Video "90876" gets videoId = 0, and video "1234" gets videoId = 1.

Watching video 0 from minute 1 to 3 returns "087" and increases its views.

After one like, the video has [1, 0] likes/dislikes and 1 total view.

Example 2:

Input:

calls = ["VideoSharingPlatform", "upload", "upload", "remove", "upload", "watch", "getViews"]

params = [[], ["55"], ["99"], [0], ["777"], [0, 0, 10], [0]]

Output: [null, 0, 1, null, 0, "777", 1]

Explanation:

The first two uploaded videos get IDs 0 and 1.

After removing video 0, that ID becomes free again.

So the next uploaded video gets videoId = 0.

Watching it returns "777" and increases its views to 1.

Now Your Turn!

Pick the correct output for the given input

Input:

calls = ["VideoSharingPlatform", "upload", "dislike", "watch", "getLikesAndDislikes", "getViews"]

params = [[], ["314"], [0], [0, 1, 2], [0], [0]]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= video.length <= 105
  • The sum of video.length over all calls to upload does not exceed 105
  • video consists only of digits
  • 0 <= videoId <= 105
  • 0 <= startMinute < endMinute < 105
  • startMinute < video.length
  • The sum of endMinute - startMinute over all calls to watch does not exceed 105
  • At most 105 total calls will be made to all functions

Fun Facts

0
class VideoSharingPlatform {
public:
VideoSharingPlatform() {
}
int upload(string video) {
}
void remove(int videoId) {
}
string watch(int videoId, int startMinute, int endMinute) {
}
void like(int videoId) {
}
void dislike(int videoId) {
}
vector<int> getLikesAndDislikes(int videoId) {
}
int getViews(int videoId) {
}
};
 
/**
* Your VideoSharingPlatform object will be instantiated and called as such:
* VideoSharingPlatform* obj = new VideoSharingPlatform();
* int param_1 = obj->upload(video);
* obj->remove(videoId);
* string param_3 = obj->watch(videoId,startMinute,endMinute);
* obj->like(videoId);
* obj->dislike(videoId);
* vector<int> param_6 = obj->getLikesAndDislikes(videoId);
* int param_7 = obj->getViews(videoId);
*/
 
Test Case

Input:

Calls
Methods
Params