Tap here to switch tabs
Problem
Submissions

Problem: Number of Student Replacements

Number of Student Replacements starts with the first student selected, then scans an array of ranks from left to right. Count each later student whose strictly better rank replaces the selection.

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

Number of Student Replacements starts with the first student selected, then scans an array of ranks from left to right. Count each later student whose strictly better rank replaces the selection.

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