Maximum Shown Segments

Maximum Shown Segments

FULLTIME

The TikTok video content analyzer, which is always eager to get the highest views, faced a unique task that required pure coding. The task provided the students with a series of video clips and posed a question based on the content in these clips. Each question involved two missions: to determine the maximum number of views and the students must find an algorithm that determines the maximum number of video views while still showing the most successful creators.

The student's task is to calculate, for each question, the maximum number of video segments that can create the highest engagement. In no valid case will be 0, as possible, the answer should be the maximum number of views that can be achieved by showing clips from the most successful creators.


Function Description

Complete the function maxShownSegments in the editor below.

maxShownSegments has the following parameters:

  • int arr[n] : an array representing the lengths of video clips
  • int k : a threshold to determine how many partitions of video segments are allowed
  • Example 1 :

    Input: arr = [5, 1, 2, 3, 1], k = 2
    Output: 3
    Explanation:

    Example 2 :

    Input: arr = [1, 3, 5, 3, 1], k = 2
    Output: 3


    Example 3 :

    Input: arr = [6, 4, 5, 1, 7], k = 5
    Output: 0
    Explanation:






    Get one-to-one training from Google Facebook engineers

    Top-notch Professionals

    Learn from Facebook and Google senior engineers interviewed 100+ candidates.
    Most recent interview questions and system design topics gathered from aonecode alumnus.
    One-to-one online classes. Get feedbacks from real interviewers.

    Customized Private Class

    Already a coding expert? - Advance straight to hard interview topics of your interest.
    New to the ground? - Develop basic coding skills with your own designated mentor.
    Days before interview? - Focus on most important problems in target company question bank.