DriveReady

P04 — Order statistics — every solution explained

This lesson is part of full access

One payment of ₹250 opens every lesson, practice set and mock for all five companies. No subscription, no expiry.

What is inside

  • 1. How many elements are strictly less than v
  • 2. How many strictly greater
  • 3. Elements with equal counts of smaller and larger ("balanced" positions)
  • 4. Rank of v = 1 + how many are strictly smaller
  • 5. k-th smallest (1-based) via sorting a copy
  • 6. Second largest DISTINCT value; Integer.MIN_VALUE if none
  • 7. Median; even length -> average of the two middles, truncating
  • 8. Is the array a permutation of 1..n?
  • 9. Leader elements: every element to the right is strictly smaller. (Named by a dated 2025 candidate report.) Scan from the right
  • 10. Equilibrium index: sum of the left part equals sum of the right part