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
Coding & Algorithms
Software Engineer
ByteDance
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
topological sort
two-level graphs
Kahn's algorithm
cycle detection
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
  • 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 Problems
Sample 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...


Submit Your Answer
Markdown supported