Tap here to switch tabs
Problem
Submissions

Problem: Number of Student Replacements

med
30 min
Try to solve the Number of Student Replacements problem.

Statement

You are given an integer array ranks, where ranks[i] represents the rank of the student at index i. A smaller value indicates a better rank.

Initially, the student at index 00 is selected. Moving through the remaining students from left to right starting from index 11, a student replaces the currently selected student if their rank is strictly better than the rank of the currently selected student.

Return the total number of student replacements that occur.

Constraints:

  • 1≤1 \leq ranks.length ≤105\leq 10^5

  • 1≤1 \leq ranks[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Student Replacements

med
30 min
Try to solve the Number of Student Replacements problem.

Statement

You are given an integer array ranks, where ranks[i] represents the rank of the student at index i. A smaller value indicates a better rank.

Initially, the student at index 00 is selected. Moving through the remaining students from left to right starting from index 11, a student replaces the currently selected student if their rank is strictly better than the rank of the currently selected student.

Return the total number of student replacements that occur.

Constraints:

  • 1≤1 \leq ranks.length ≤105\leq 10^5

  • 1≤1 \leq ranks[i] ≤105\leq 10^5