Solve snake game, peak search, and task scheduling
Problem 1: Snake Game Simulation
Design a grid-based snake simulation that supports move(direction) operations on a W×H board. The snake grows when it consumes food at predetermined coordinates. After each move, return the current score, or -1 if the snake hits a wall or itself.
- Specify the data structures required to achieve O(1) average time per move.
- Explain how you detect collisions (with walls and the snake's own body).
- Describe how the food pointer is advanced after consumption.
Problem 2: Peak Search in Array
Given an integer array nums, find any index i such that nums[i] is strictly greater than its immediate neighbors (nums[i-1] and nums[i+1]). This is considered a local peak.
- The algorithm must run in O(log n) time and O(1) space.
- Describe the algorithm and prove its correctness.
- Discuss adaptations required when duplicate numbers are allowed in the array.
Problem 3: Task Scheduling with Cooldown
You are given a list of tasks, identified by characters (e.g., 'A', 'B', 'C'), and a non-negative cooldown n.
- Compute the minimum number of time slots required to finish all tasks, assuming each slot can execute one task or be idle.
- Outline how to construct one valid schedule.
- Extend your approach to handle distinct cooldowns for each task.
AI interview prep
Core dilemma
Demonstrating breadth of algorithmic and data structure knowledge across distinct problem domains (simulation, search, scheduling) under strict performance constraints, while managing the time allocation for each sub-problem.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Solve snake game, peak search, and task scheduling
Problem 1: Snake Game Simulation
Design a grid-based snake simulation that supports move(direction) operations on a W×H board. The snake grows when it consumes food at predetermined coordinates. After each move, return the current score, or -1 if the snake hits a wall or itself.
- Specify the data structures required to achieve O(1) average time per move.
- Explain how you detect collisions (with walls and the snake's own body).
- Describe how the food pointer is advanced after consumption.
Problem 2: Peak Search in Array
Given an integer array nums, find any index i such that nums[i] is strictly greater than its immediate neighbors (nums[i-1] and nums[i+1]). This is considered a local peak.
- The algorithm must run in O(log n) time and O(1) space.
- Describe the algorithm and prove its correctness.
- Discuss adaptations required when duplicate numbers are allowed in the array.
Problem 3: Task Scheduling with Cooldown
You are given a list of tasks, identified by characters (e.g., 'A', 'B', 'C'), and a non-negative cooldown n.
- Compute the minimum number of time slots required to finish all tasks, assuming each slot can execute one task or be idle.
- Outline how to construct one valid schedule.
- Extend your approach to handle distinct cooldowns for each task.