Autocoder

Dream11 Coding Round Questions with Solutions

Last updated 2026-11-19

A fantasy-sports app has a very particular shape: millions of users pick eleven players, a match produces a stream of ball-by-ball events, and every few seconds a leaderboard has to be recomputed and a prize pool divided. Dream11 does not publish how it tests candidates and this site holds no sourced account of its rounds, so treat this page as practice built on that domain rather than a forecast of any paper.

The ten problems below walk through the product end to end: scoring an innings, choosing a squad under a credit cap, ranking users with ties, keeping a live top list, and sharing out a pool. Each has Python and Java code, a stated cost and the slips that tend to cost marks. For concept questions and HR practice see Dream11 interview questions; for method under a timer see how to crack the DSA coding round.

Where the load actually sits in a fantasy platform

Traffic peaks sharply around a toss and the first over, so the interesting engineering is not storing data but ranking and re-ranking it quickly. That is why heaps, sorted structures and windows over a stream appear again and again in the problems here.

A second theme is fairness in money handling. Ties in rank, rounding of prize shares and duplicate entries are all places where a clever algorithm still produces a wrong payout, so each answer calls out the edge case in plain words.

Hiring status

We hold no sourced hiring statement for Dream11 and there is no page for it under /hiring. Use the careers page on the company's own website for current roles and the actual selection steps.

Dream11 Coding Round Questions with Solutions: questions with worked answers

  1. 1

    Score a player's innings from ball-by-ball events with a captain and vice-captain multiplier.

    easy

    Map each event type to a fixed point value, sum per player in one pass, then apply the multiplier: double for the captain and one and a half for the vice-captain. To avoid floating point, return half-points so the multipliers become 4 and 3 against a normal 2. One pass over the events, linear time. A frequent error is multiplying the captain's bonus points but not the base points, or applying both multipliers when one player is somehow listed twice.

    python
    from collections import defaultdict
    
    POINTS = {'run': 1, 'four': 1, 'six': 2, 'wicket': 25, 'catch': 8, 'duck': -2}
    
    def team_points(events, captain, vice):
        base = defaultdict(int)
        for player, kind in events:
            base[player] += POINTS[kind]
        mult = {captain: 4, vice: 3}          # half-points: normal is 2
        return {p: v * mult.get(p, 2) for p, v in base.items()}
    java
    import java.util.*;
    
    static final Map<String, Integer> PTS = Map.of("run", 1, "four", 1, "six", 2, "wicket", 25, "catch", 8, "duck", -2);
    
    static Map<String, Integer> teamPoints(List<String[]> events, String captain, String vice) {
        Map<String, Integer> tot = new HashMap<>();
        for (String[] e : events) tot.merge(e[0], PTS.get(e[1]), Integer::sum);
        tot.replaceAll((p, v) -> v * (p.equals(captain) ? 4 : p.equals(vice) ? 3 : 2));
        return tot;
    }
  2. 2

    Choose exactly 11 players with the highest projected points while keeping total credits within a cap.

    hard

    This is a knapsack with an extra dimension for head count. Let dp[k][c] be the best points using k players and exactly c credits. Process players one at a time, looping k and c downwards so a player is used once, and finally take the best value in row 11. Store credits as integers in tenths, so 9.5 becomes 95. Time O(players x 11 x cap). Looping upwards lets one star be picked twice, and using fractional credits as array indexes simply does not work.

    python
    def best_team(players, size=11, cap=1000):    # players: (points, credits_in_tenths)
        dp = [[-1] * (cap + 1) for _ in range(size + 1)]
        dp[0][0] = 0
        for pts, cr in players:
            for k in range(size - 1, -1, -1):
                for c in range(cap - cr, -1, -1):
                    if dp[k][c] >= 0 and dp[k][c] + pts > dp[k + 1][c + cr]:
                        dp[k + 1][c + cr] = dp[k][c] + pts
        return max(dp[size])                         # -1 when no valid team exists
    java
    static int bestTeam(int[] pts, int[] cr, int size, int cap) {
        int[][] dp = new int[size + 1][cap + 1];
        for (int[] row : dp) java.util.Arrays.fill(row, -1);
        dp[0][0] = 0;
        for (int i = 0; i < pts.length; i++)
            for (int k = size - 1; k >= 0; k--)
                for (int c = cap - cr[i]; c >= 0; c--)
                    if (dp[k][c] >= 0)
                        dp[k + 1][c + cr[i]] = Math.max(dp[k + 1][c + cr[i]], dp[k][c] + pts[i]);
        int best = -1;
        for (int v : dp[size]) best = Math.max(best, v);
        return best;
    }
  3. 3

    Assign ranks to contest entries so that equal scores share a rank and the next rank is skipped.

    easy

    Sort scores in descending order and record, for each distinct score, the position where it first appears, counting from one. Equal scores then map to the same rank and the following score lands at its natural position, giving 1, 2, 2, 4. Sorting dominates at O(n log n). Using the loop index directly gives every tied user a different rank, and using a dense scheme (1, 2, 2, 3) changes who qualifies for a prize band, so confirm which scheme the question wants.

    python
    def contest_ranks(scores):
        first = {}
        for pos, s in enumerate(sorted(scores, reverse=True), 1):
            first.setdefault(s, pos)
        return [first[s] for s in scores]
    java
    import java.util.*;
    
    static int[] contestRanks(int[] scores) {
        int n = scores.length;
        int[] asc = scores.clone();
        Arrays.sort(asc);
        Map<Integer, Integer> first = new HashMap<>();
        for (int i = n - 1; i >= 0; i--) first.putIfAbsent(asc[i], n - i);
        int[] ranks = new int[n];
        for (int i = 0; i < n; i++) ranks[i] = first.get(scores[i]);
        return ranks;
    }
  4. 4

    Keep a live top-k leaderboard while users' scores keep increasing.

    hard

    Store the current score per user in a map and push a fresh (score, user) entry onto a max-heap on every update, leaving older entries in place. When asked for the top k, pop entries and skip any whose score no longer matches the map or whose user was already reported, then push the valid ones back. Updates cost O(log n); a query costs O(k log n) amortised. Editing heap entries in place is not possible with standard libraries, and forgetting to skip stale entries reports one user twice.

    python
    import heapq
    
    class LiveBoard:
        def __init__(self):
            self.score, self.heap = {}, []
    
        def update(self, user, pts):
            self.score[user] = self.score.get(user, 0) + pts
            heapq.heappush(self.heap, (-self.score[user], user))
    
        def top(self, k):
            out, seen, keep = [], set(), []
            while self.heap and len(out) < k:
                neg, user = heapq.heappop(self.heap)
                if self.score[user] != -neg or user in seen:
                    continue                      # stale entry, drop it
                out.append((user, -neg))
                seen.add(user)
                keep.append((neg, user))
            for item in keep:
                heapq.heappush(self.heap, item)
            return out
    java
    import java.util.*;
    
    class LiveBoard {
        record E(String user, int score) {}
        private final Map<String, Integer> score = new HashMap<>();
        private final PriorityQueue<E> heap = new PriorityQueue<>(
            (a, b) -> a.score() != b.score() ? b.score() - a.score() : a.user().compareTo(b.user()));
        void update(String user, int pts) {
            int s = score.merge(user, pts, Integer::sum);
            heap.add(new E(user, s));
        }
        List<String> top(int k) {
            List<String> out = new ArrayList<>();
            List<E> keep = new ArrayList<>();
            Set<String> seen = new HashSet<>();
            while (!heap.isEmpty() && out.size() < k) {
                E e = heap.poll();
                if (score.get(e.user()) != e.score() || !seen.add(e.user())) continue;
                out.add(e.user() + ":" + e.score());
                keep.add(e);
            }
            heap.addAll(keep);
            return out;
        }
    }
  5. 5

    Divide a prize pool by rank, letting tied users split the prizes of the ranks they occupy.

    medium

    Sort users by score, then sweep groups of equal scores. A group occupying ranks i to j-1 pools the prizes for those ranks and shares them equally using integer division. The paise left over go one each to the earliest entries in the group, so the total paid equals the pool exactly. O(n log n) for the sort and linear after. The two slips are paying each tied user the prize of the top rank in the group, and silently dropping the remainder.

    python
    def split_prizes(scores, prizes):      # prizes[i] is the payout for rank i+1, in paise
        order = sorted(range(len(scores)), key=lambda i: -scores[i])
        pay = [0] * len(scores)
        i = 0
        while i < len(order):
            j = i
            while j < len(order) and scores[order[j]] == scores[order[i]]:
                j += 1
            pool = sum(prizes[i:j])
            share, rem = divmod(pool, j - i)
            for n, u in enumerate(sorted(order[i:j])):
                pay[u] = share + (1 if n < rem else 0)
            i = j
        return pay
    java
    import java.util.*;
    
    static long[] splitPrizes(int[] scores, long[] prizes) {
        int n = scores.length;
        Integer[] order = new Integer[n];
        for (int i = 0; i < n; i++) order[i] = i;
        Arrays.sort(order, (a, b) -> scores[b] - scores[a]);
        long[] pay = new long[n];
        int i = 0;
        while (i < n) {
            int j = i;
            while (j < n && scores[order[j]] == scores[order[i]]) j++;
            long pool = 0;
            for (int r = i; r < j && r < prizes.length; r++) pool += prizes[r];
            int[] grp = new int[j - i];
            for (int r = i; r < j; r++) grp[r - i] = order[r];
            Arrays.sort(grp);
            long share = pool / grp.length, rem = pool % grp.length;
            for (int r = 0; r < grp.length; r++) pay[grp[r]] = share + (r < rem ? 1 : 0);
            i = j;
        }
        return pay;
    }
  6. 6

    Find the highest points total in every window of k consecutive balls.

    medium

    Keep a deque of indexes whose values are in decreasing order. For each new ball, pop smaller values from the back, push the new index, drop the front if it has left the window, and read the maximum from the front once the first window is full. Every index enters and leaves once, so O(n) time with O(k) space. Re-scanning each window costs O(nk), and storing values rather than indexes makes expiry impossible to detect.

    python
    from collections import deque
    
    def window_max(a, k):
        dq, out = deque(), []
        for i, x in enumerate(a):
            while dq and a[dq[-1]] <= x:
                dq.pop()
            dq.append(i)
            if dq[0] <= i - k:
                dq.popleft()
            if i >= k - 1:
                out.append(a[dq[0]])
        return out
    java
    import java.util.*;
    
    static int[] windowMax(int[] a, int k) {
        ArrayDeque<Integer> dq = new ArrayDeque<>();
        int[] out = new int[Math.max(0, a.length - k + 1)];
        for (int i = 0; i < a.length; i++) {
            while (!dq.isEmpty() && a[dq.peekLast()] <= a[i]) dq.pollLast();
            dq.addLast(i);
            if (dq.peekFirst() <= i - k) dq.pollFirst();
            if (i >= k - 1) out[i - k + 1] = a[dq.peekFirst()];
        }
        return out;
    }
  7. 7

    Longest streak of consecutive match numbers a user has joined contests for.

    medium

    Put all match numbers in a hash set. A streak can only begin at a number whose predecessor is missing, so for each such start count upwards while the next number exists. Each number is visited at most twice, giving O(n) expected time. Sorting also works at O(n log n) but needs care with duplicates. The usual bug is starting a count from every element, which turns the loop quadratic on a long run.

    python
    def longest_streak(match_ids):
        seen, best = set(match_ids), 0
        for x in seen:
            if x - 1 not in seen:
                y = x
                while y + 1 in seen:
                    y += 1
                best = max(best, y - x + 1)
        return best
    java
    import java.util.*;
    
    static int longestStreak(int[] ids) {
        Set<Integer> seen = new HashSet<>();
        for (int x : ids) seen.add(x);
        int best = 0;
        for (int x : seen) {
            if (seen.contains(x - 1)) continue;
            int y = x;
            while (seen.contains(y + 1)) y++;
            best = Math.max(best, y - x + 1);
        }
        return best;
    }
  8. 8

    In how many different ball-by-ball sequences can a batter score exactly T runs in one over?

    medium

    Each ball yields 0, 1, 2, 3, 4 or 6 runs and order matters. Run a DP across the six balls: ways[s] is the number of sequences so far that total s, and each new ball spreads every ways[s] to s plus an outcome, capped at T. Time is balls x T x outcomes. Sanity check: summing over all targets must give 6 to the power 6. Counting multisets rather than sequences, as a coin-change loop would, answers a different question.

    python
    def over_ways(target, balls=6, outcomes=(0, 1, 2, 3, 4, 6)):
        dp = [0] * (target + 1)
        dp[0] = 1
        for _ in range(balls):
            nxt = [0] * (target + 1)
            for s, w in enumerate(dp):
                if w:
                    for o in outcomes:
                        if s + o <= target:
                            nxt[s + o] += w
            dp = nxt
        return dp[target]
    java
    static long overWays(int target) {
        int[] outcomes = {0, 1, 2, 3, 4, 6};
        long[] dp = new long[target + 1];
        dp[0] = 1;
        for (int ball = 0; ball < 6; ball++) {
            long[] nxt = new long[target + 1];
            for (int s = 0; s <= target; s++)
                if (dp[s] > 0)
                    for (int o : outcomes)
                        if (s + o <= target) nxt[s + o] += dp[s];
            dp = nxt;
        }
        return dp[target];
    }
  9. 9

    Detect users who entered the same team, with the same captain and vice-captain, twice into a contest.

    easy

    Build a canonical key for each entry: the sorted list of eleven players plus the captain and vice-captain. Keep a map from key to the first entry index and report every later entry whose key is already present. Sorting eleven names is constant work per entry, so the whole pass is linear in the number of entries. Hashing the unsorted list treats the same squad in a different order as distinct, and ignoring the captain would wrongly merge genuinely different teams.

    python
    def duplicate_entries(entries):        # entries: (players, captain, vice)
        first, dups = {}, []
        for idx, (players, cap, vice) in enumerate(entries):
            key = (tuple(sorted(players)), cap, vice)
            if key in first:
                dups.append((first[key], idx))
            else:
                first[key] = idx
        return dups
    java
    import java.util.*;
    
    static List<int[]> duplicateEntries(List<String[]> teams) {   // {captain, vice, players...}
        Map<String, Integer> first = new HashMap<>();
        List<int[]> dups = new ArrayList<>();
        for (int i = 0; i < teams.size(); i++) {
            String[] t = teams.get(i);
            String[] players = Arrays.copyOfRange(t, 2, t.length);
            Arrays.sort(players);
            String key = String.join(",", players) + "|" + t[0] + "|" + t[1];
            Integer prev = first.putIfAbsent(key, i);
            if (prev != null) dups.add(new int[]{prev, i});
        }
        return dups;
    }
  10. 10

    Longest run of balls in which at most k are dot balls.

    medium

    Encode each ball as 1 for runs and 0 for a dot. Slide a window with a count of zeros inside it; when the count exceeds k, advance the left edge until it is back to k, and record the widest window seen. Each pointer only moves forward, so O(n) time and O(1) space. The mistake is shrinking the window after every step instead of only when the limit is broken, which finds the right answer on small samples and a wrong one on others.

    python
    def longest_run(balls, k):
        left = zeros = best = 0
        for right, b in enumerate(balls):
            if b == 0:
                zeros += 1
            while zeros > k:
                if balls[left] == 0:
                    zeros -= 1
                left += 1
            best = max(best, right - left + 1)
        return best
    java
    static int longestRun(int[] balls, int k) {
        int left = 0, zeros = 0, best = 0;
        for (int right = 0; right < balls.length; right++) {
            if (balls[right] == 0) zeros++;
            while (zeros > k) {
                if (balls[left] == 0) zeros--;
                left++;
            }
            best = Math.max(best, right - left + 1);
        }
        return best;
    }

Frequently asked questions

Does Dream11 ask fantasy-sports questions in its coding round?

There is no sourced account of its rounds, so do not assume it. The domain here is a practice device: ranking, windows and money-splitting problems build the same skills any product company test checks.

Which data structure matters most for leaderboards?

A heap or a balanced ordered structure, because the operation you repeat is finding the best few items among many that keep changing. Know how to handle stale entries when a key's priority changes.

How should I handle ties in a ranking question?

Ask which rank scheme is wanted before coding. Competition ranking skips numbers after a tie, dense ranking does not, and the choice changes which users sit inside a prize band.

How many problems of this kind should I practise per week?

Five or six done properly beats twenty skimmed. Re-solve any problem you needed hints for from a blank file two days later and note which edge case you missed.

Related guides

More in Company Interview Questions

See all in this section