Students are standing in a fixed row. The marks received by the ith student are stored in marks.get(i).
The row is properly grouped when all students having the same marks stand together in one continuous group.
The students cannot change positions, but their recorded marks can be updated. Find the minimum number of student records that must be changed to properly group the row.
oldMarks and newMarks.oldMarks to newMarks.oldMarks is not allowed.StudentMarksOrganizer
StudentMarksOrganizer()
int minimumMarkChanges(List<Integer> marks)
marks.get(i) contains the marks of the ith student.1 ≤ marks.size() ≤ 100,000-1,000,000,000 ≤ marks.get(i) ≤ 1,000,000,000marks is non-null.O(n) expected time.O(n) additional space. minimumMarkChanges(marks = List.of(80, 60, 80, 70, 70, 90))
Output: 1
Change every mark of 60 to 80. The marks become [80, 80, 80, 70, 70, 90].
minimumMarkChanges( marks = List.of(50, 70, 50, 90, 70, 40, 90, 40))
Output: 6
Change every 70, 90, and 40 to 50. Each operation changes two records, so the total cost is 6.
minimumMarkChanges(marks = List.of(100, 100, -5, -5, 75))
Output: 0
Students having the same marks are already together.
minimumMarkChanges( marks = List.of(60, 40, 60, 90, 75, 90, 30, 30))
Output: 2
Change every 40 to 60 and every 75 to 90. The marks become [60, 60, 60, 90, 90, 90, 30, 30].