Settle a Weekly League With Promotion and Demotion Zones

Last updated: November 29, 2026

Quick Overview

At the end of a League week, each of up to 30 learners has a total XP and the timestamp at which they reached it. Rank them, then label each learner promote, stay or demote given the size of the promotion and demotion zones, where anyone with zero XP is always demoted.

Duolingo
Coding & Algorithms
Software Engineer
Duolingo
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


At the end of a League week, each of up to 30 learners has a total XP and the timestamp at which they reached it. Rank them, then label each learner promote, stay or demote given the size of the promotion and demotion zones, where anyone with zero XP is always demoted.

Leagues drive weekly engagement at Duolingo, and settling them correctly matters because learners notice any unfair rank. In an online assessment this tests sorting with a compound key and careful handling of zone boundaries and ties.

What the Interviewer Expects
  • Sorts by XP descending and breaks ties by who reached the XP first
  • Adds a final deterministic tiebreak such as user id
  • Applies the zero-XP rule before the zone rules
  • Handles leagues smaller than promote plus demote without double-labeling
  • Returns a mapping that is easy to persist
Key Topics to Cover
Custom sort keys
Tie breaking
Boundary conditions
Idempotent batch jobs
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if the promote and demote zones overlap in a league of 12 people?
  • How would you settle millions of leagues in a batch job at the week boundary?
  • How should the top league, which has no promotion, be handled?
  • How would you make settlement idempotent if the job is retried?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: list of (user_id, xp, reached_at), plus promote (top N) and demote (bottom M). Ties on XP go to whoever reached that total earlier, then by user id so results are deterministic. Zero-XP l...

High-Level Design

One sort with key (-xp, reached_at, user_id). Then a single pass by rank index assigns labels: zero XP first, then index below promote, then index in the last demote slots, else stay....


Submit Your Answer
Markdown supported

Related Questions