Solve snake game, peak search, and task scheduling
Company: IXL Learning
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
1) 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; return the score after each move or -1 if the snake hits a wall or itself. Specify the data structures to achieve O(
1) average time per move and explain how you detect collisions and advance the food pointer.
2) Given an integer array, find any index i such that nums[i] is strictly greater than its immediate neighbors (a local peak) in O(log n) time and O(
1) space. Describe the algorithm, prove correctness, and discuss adaptations when duplicates are allowed.
3) You are given tasks identified by characters and a non-negative cooldown n. Compute the minimum number of time slots to finish all tasks if each slot can execute one task or be idle, and outline how to construct one valid schedule. Extend your approach to handle distinct cooldowns per task.
Quick Answer: This multipart question evaluates data-structure design and real-time simulation skills for a snake game, logarithmic-time search and proof-based reasoning for peak finding, and combinatorial scheduling and greedy/analytic reasoning for task cooldown optimization, covering complexity analysis, collision handling, and schedule construction.