BackmediumArrays Microsoft

Merging Segments of Student Performance Solution

Problem Statement

The school administration wants to evaluate the performance of its students by merging their scores in different subjects and providing an overall grade. The scores are initially provided in the form of an array where each element represents a segment of scores. The segments are marked with a specific ID. The task is to create a new merged array with overall scores for each segment, and sort them.

Example 1
Input
[[15, 'S1'], [15, 'S1'], [9, 'S1']]
Output
[[15, 'S1'], [15, 'S1'], [9, 'S1']]

Explanation: Step 1: Initialize an empty dictionary to store segment scores. Step 2: Iterate through the input array. For each segment, check if it exists in the dictionary. If it does, add the score to the existing value. If it doesn't, add the segment to the dictionary with its score. Step 3: Convert the dictionary to a list of lists and sort it.

Example 2
Input
[[15, 'S2'], [15, 'S2'], [4, 'S2']]
Output
[[15, 'S2'], [15, 'S2'], [4, 'S2']]

Explanation: Step 1: Initialize an empty dictionary to store segment scores. Step 2: Iterate through the input array. For each segment, check if it exists in the dictionary. If it does, add the score to the existing value. If it doesn't, add the segment to the dictionary with its score. Step 3: Convert the dictionary to a list of lists and sort it.

Constraints

  • Each segment can have at most 3 test scores.
  • The scores can be in the range of 0-100.
  • All segment IDs are unique.
  • Array size is ≤ 10^5.
  • The scores are non-negative integers.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free