FastPrepCount Students Outside Their Sorted Positions
Problems/Count Students Outside Their Sorted Positions

Count Students Outside Their Sorted Positions

Concentric AI logoConcentric AI● EasyFULLTIMEOA

Updated Aug 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The original report directly identifies sorting the supplied heights and counting positions whose values change. This practice version uses a bounded integer-array interface.

You are given an array heights, where heights[i] is the height of the student currently standing at index i.

The students should stand in nondecreasing height order. Return the number of indices whose current height differs from the height that would appear at that index after sorting the entire array.

Function

countStudentsOutOfPosition(heights: int[]) → int

Examples

Example 1

heights = [1,1,4,2,1,3]return = 3

The sorted array is [1,1,1,2,3,4]. Indices 2, 4, and 5 differ.

Example 2

heights = [5,1,2,3,4]return = 5

After sorting, every index contains a different height.

Example 3

heights = [1,2,2,4]return = 0

The students are already in nondecreasing order.

Constraints

  • 1 <= heights.length <= 100000
  • 1 <= heights[i] <= 1000000000

More Concentric AI interview questions

  • Kth Greater Element Index to the RightOA · Seen Sep 2026
  • Find the Intersection Node of Two Linked ListsOA · Seen Sep 2026
  • Maximum Profit Under a Bitwise OR LimitOA · Seen Aug 2026
  • Minimum Weighted Manhattan Travel CostOA · Seen Aug 2026
  • Rearrange a Linked List from Alternating EndsONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Macaron Order with Set DiscountsShopify · OAShopify interview questions
  • Build the Task HierarchyPendo · OA
  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Competition Winner and Runner-Up (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
  • Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
  • Rank Football TeamsCapital One · OACapital One interview questions
  • Maximum Apples That Fit in a BoxVirtu Financial · OAVirtu Financial interview questions
  • Rank Football TeamsPersona · OAPersona interview questions
  • Meandering ArrayVerisk · OA
All Concentric AI interview questionsSee Concentric AI hiring insights
Saved
class Solution {
    public int countStudentsOutOfPosition(int[] heights) {
        // Write your code here.
    }
}
Checking account…