ZS Coding Question – Solved

12 Live
A class has students with various talents, each represented by an integer from 1 to talentsCount. You need to form teams for a quiz competition, where each team must have at least one member with each talent. Teams must be formed from consecutive students in the array. For each possible starting position, determine the minimum number of students needed to form a valid team. If it is not possible to form a team with all talents from a particular starting position, return -1 for that position. Example talentsCount = 3 talent = [1, 2, 3, 2, 1] · Starting at position 1: [1, 2, 3] includes all talents, minimum size = 3 · Starting at position 2: [2, 3, 2, 1] is the smallest subarray with all talents, minimum size = 4 · Starting at position 3: [3, 2, 1] includes all talents, minimum size = 3 Starting at positions 4 and 5: Cannot form a team with all talents, return -1 The result [3, 4, 3, -1, -1]. Function Description Complete the function teamSize in the editor with the following parameter(s): int talent[n]: the students' talents int talentsCount: the number of talents represented numbered from 1 to talentsCount Returns int[n]: at each index, the minimum size subarray required, or -1 if an appropriate subarray does not exist Constraints · 1 ≤ n, talentsCount ≤ 10^5 · 1 ≤ talent[i] ≤ talentsCount

Asked in: ZS

Image of the Question

Question Image Question Image Question Image

All Testcases Passed ✔



Passcode Image

Solution


def teamSize(talent, talentsCount):
    # Write your code here
    answer = [-1 for i in talent]
    j = 0
// ... rest of solution available after purchase

🔒 Please login to view the solution

Explanation


No explanation available for this question.


Related Questions