Implement a Cross-Sectional Rank Operator With Ties and Gaps
Last updated: November 29, 2026
Quick Overview
Given one day's alpha values for a universe of instruments, some missing, return each instrument's rank scaled to [0, 1], giving tied values their average rank and leaving missing values missing.
Worldquant
November 29, 20260
0
0 solved
Given one day's alpha values for a universe of instruments, some missing, return each instrument's rank scaled to [0, 1], giving tied values their average rank and leaving missing values missing.
Ranking across instruments on each date is one of the most used operators on WorldQuant BRAIN because it removes scale and outliers from raw signals. An online assessment checks that a candidate handles the boring but important details: ties, NaN, and degenerate universes.
What the Interviewer Expects
- Excludes missing values from the ranking rather than treating them as zero
- Assigns tied values the average of their positions
- Scales to [0, 1] by dividing by n minus 1
- Handles one valid value and all missing inputs without dividing by zero
- Runs in O(n log n)
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you vectorize this across thousands of dates with numpy?
- What changes if the rank should be computed within each industry group?
- Why is rank often preferred to z-scoring a raw signal?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: a list of floats, with None or NaN for instruments that have no signal today. Output: same length list, each valid entry mapped to its rank divided by (valid count minus 1), ties sharing the av...
High-Level Design
Collect (value, original index) for valid entries, sort by value, then walk the sorted list in blocks of equal values. Each block of positions i..j gets average position (i+j)/2, scaled by n-1, and is...