Heap pattern

Relative Ranks

Given distinct scores, return each athlete’s rank in the same order as the input. The top three receive "Gold Medal", "Silver Medal" and "Bronze Medal"; the rest receive their placement number as a string. Watch it run step by step, then write your own pseudocode and get it checked by AI.

  • LeetCode 506
  • Easy
  • 2 approaches

Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.

HeapLeetCode 506

Easy

From the first idea to the best one

  1. 01 Brute force · count who beat you O(n²)O(n) space
  2. 02 Optimized · sort the indices O(n log n)O(n) space
Each approach plays step by step, with its time and space.

What you will learn

  • How to read Relative Ranks and spot the heap pattern in it
  • Brute force · count who beat you: O(n²) time, O(n) space
  • Optimized · sort the indices: O(n log n) time, O(n) space
  • The pseudocode for each approach, its line lit as the animation runs
  • Practice: write your own pseudocode and get it checked

More Heap

See Relative Ranks run, step by step

Sign in and this page opens on the animation, with all 7 Heap problems beside it.

DSA comes with the all labs plan and every ChaiCode batch.