Order Lark Project Tasks So Each Team's Work Stays Contiguous
Last updated: November 29, 2026
Quick Overview
Each of n tasks in a Lark project board belongs to a team (or none, marked -1) and has a list of prerequisite tasks; return an order that respects all prerequisites and keeps every team's tasks adjacent, or an empty list if impossible.
ByteDance
November 29, 20260
0
0 solved
Each of n tasks in a Lark project board belongs to a team (or none, marked -1) and has a list of prerequisite tasks; return an order that respects all prerequisites and keeps every team's tasks adjacent, or an empty list if impossible.
Lark's project management features need to lay out cross-team work so teams can hand off cleanly, and this two-level topological sort is a classic ByteDance onsite Hard. The interviewer checks whether you separate group-level and item-level ordering and handle ungrouped items without special cases.
What the Interviewer Expects
- Give each ungrouped task its own unique team id
- Build an item graph and a team graph from the same prerequisites
- Topologically sort both and fail if either has a cycle
- Bucket the item order by team, then emit teams in team order
- Explain O(n + E) time
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
- Return a lexicographically smallest valid order.
- Teams can be split into at most two contiguous blocks: what changes?
- How would you explain to a user which dependency makes the plan impossible?
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: n, team[i] in [-1, m), and before[i], the prerequisite tasks of i. Output: a permutation where prerequisites come first and each team's tasks form one contiguous block. Return [] when no such o...
High-Level Design
Two observations make this tractable. First, ungrouped tasks behave like singleton teams, so relabel them with fresh ids. Second, a valid answer is a valid team order with a valid within-team order in...