Scale AI software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
Subsequence Goodness Values
Input: Arrayclass TaskScheduler: def add_task(self, task_id: str, dependencies: List[str]) -> None: # Adds a new task with its dependencies.def schedule_tasks(self) -> List[str]: # Returns a list of tasks in the order they should be executed.Example 1: add_task('A', []) add_task('B', ['A']) add_task('C', ['A']) ['A', 'B', 'C'] add_task('D', ['E']) add_task('E', []) ['E', 'D'] def schedule_tasks(tasks: List[str], dependencies: List[Tuple[str, str]]) -> List[str]: tasks = ['A', 'B', 'C'], dependencies = [('A', 'B'), ('B', 'C')] ['C', 'B', 'A'] tasks = ['A', 'B', 'C', 'D'], dependencies = [('A', 'B'), ('B', 'C'), ('D', 'B')] ['D', 'C', 'B', 'A'] def add_task(self, task_id: str, dependencies: List[str]) -> None: def execute(self) -> List[str]: scheduler.add_task('A', []) scheduler.add_task('B', ['A']) scheduler.execute() ['A', 'B'] scheduler.add_task('C', ['D']) scheduler.add_task('D', []) scheduler.add_task('A', ['C']) scheduler.execute() ['D', 'C', 'A'] def schedule_tasks(tasks: List[int], dependencies: List[Tuple[int, int]]) -> List[int]: tasks = [1, 2, 3], dependencies = [(1, 2), (1, 3)][1, 2, 3]tasks = [1, 2, 3], dependencies = [(1, 2), (2, 1)][]1 ≤ len(tasks) ≤ 10001 ≤ len(dependencies) ≤ 5000[1, len(tasks)].def task_scheduler(tasks: List[int], dependencies: List[Tuple[int, int]]) -> List[int]:tasks = [1, 2, 3, 4], dependencies = [(1, 2), (1, 3), (3, 4)][1, 3, 4, 2] (possible output)tasks = [1, 2, 3], dependencies = [(1, 2), (2, 1)][]TaskScheduler that manages a list of tasks, each with a set of dependencies. You will need to create a method schedule_tasks that takes the list of tasks and their dependencies and returns an ordered list of tasks that can be executed respecting the dependencies. If there are circular dependencies, return an empty list. def schedule_tasks(tasks: List[str], dependencies: List[Tuple[str, str]]) -> List[str]: tasks = ['A', 'B', 'C', 'D']
dependencies = [('A', 'B'), ('B', 'C'), ('C', 'D')] ['D', 'C', 'B', 'A']
D can be completed first as it has no dependencies, followed by C, B, and finally A. tasks = ['A', 'B', 'C']
dependencies = [('A', 'B'), ('B', 'A')] []
A and B, making it impossible to schedule them. 1 <= len(tasks) <= 10^4 0 <= len(dependencies) <= 10^4 Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free