FastPrepFastPrep
Problem Brief

Maximum Shown Segments

FULLTIMEOA
See Tiktok online assessment and hiring insights

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


1Example 1

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

2Example 2

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

3Example 3

Input
arr = [6, 4, 5, 1, 7], k = 5
Output
0
Explanation
Example 3 illustration
public int maxShownSegments(int[] arr, int k) {
  // write your code here
}
Input

arr

[5, 1, 2, 3, 1]

k

2

Output

3

Sign in to submit your solution.