Settle Team Purchase Groups Before Their Deadline
Last updated: November 29, 2026
Quick Overview
Given open team-purchase groups (creation time, required size, leader) and a time-ordered stream of join events, return which groups completed and when, and which groups failed because the 24-hour window expired.
Pinduoduo
November 29, 20260
0
0 solved
Given open team-purchase groups (creation time, required size, leader) and a time-ordered stream of join events, return which groups completed and when, and which groups failed because the 24-hour window expired.
Team purchase (pin tuan) is the core Pinduoduo mechanic: a shopper opens a group at a discounted price and it only ships if enough people join before the timer runs out. This warm-up checks whether you turn a product rule into clean state handling: dedupe users, ignore late or post-completion joins, and treat the leader as a member.
What the Interviewer Expects
- Counts the leader as the first member of the group
- Ignores duplicate joins from the same user
- Rejects joins after the window closes or after the group is already full
- Records completion at the timestamp of the join that filled the group
- Runs in O(J log J) for sorting plus O(1) work per join
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 handle a member cancelling their payment before the group fills?
- Joins arrive out of order from several regions. What changes?
- How would you emit refunds for failed groups in real time rather than at the end?
- A size-1 group is created. What should happen?
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: groups maps gid -> (created_at, size_required, leader_id) and joins is a list of (ts, gid, user_id). A join counts only if the group exists, the timestamp is inside `[created_at, create...
High-Level Design
Keep a member set per group seeded with the leader, and a completed map. Walk the joins in timestamp order. When a valid join makes the set size equal size_required, record the completion time. An...