Solve common data-structure and puzzle problems
Coding and Algorithm Problems
This interview consists of a series of independent coding and algorithm problems. You should solve them using a language of your choice, assuming typical 32/64-bit integer constraints.
1. Reverse a Singly Linked List
Given the head of a singly linked list, reverse it and return the new head. You may implement either an iterative or a recursive solution, or both.
2. Numbering on an Outward Spiral Grid
Integers are written on an infinite 2D grid starting with 1 at (0,0), then 2 at (1,0), and continuing counterclockwise in an outward square spiral (moving right, then up, then left, then down, and so on). Given integer coordinates (x, y), compute the value written at that cell. Your solution must run in O(1) time, without simulating the spiral.
3. 100 Bulbs Toggling
There are 100 light bulbs, labeled 1 through 100, all initially OFF. Person 1 toggles every bulb. Person 2 toggles bulbs 2, 4, 6, .... Person 3 toggles bulbs 3, 6, 9, ..., and this pattern continues until Person 100 toggles bulb 100. Determine which bulbs are ON at the end of this process.
4. Delete a Node with Only That Node's Pointer
You are given a pointer or reference to a specific node p within a singly linked list. You do not have access to the head pointer of the list. Delete node p from the list in O(1) time. State any required assumptions for your solution.
5. Bridge-and-Torch Scheduling
Four people need to cross a bridge at night, and they have only one torch. At most two people can cross the bridge at a time, and anyone crossing must carry the torch. The individual crossing times for the four people are 1, 2, 5, and 6 minutes. When two people cross together, the pair's crossing time is determined by the slower person's time. Find a schedule that allows everyone to cross the bridge in 13 minutes or less, or prove that it is impossible.
6. Validate a Binary Search Tree (BST)
Given the root of a binary tree, determine whether it satisfies the binary search tree property.
7. Merge Intervals
Given a list of intervals, where each interval is represented as [start, end] (inclusive), merge all overlapping intervals and return the merged list.
8. Maximum Adjacent Gap After Sorting
Given an unsorted array of integers, determine the maximum difference between two adjacent elements in the sorted version of the array. Design an algorithm that is better than O(n log n) time complexity if possible, and state any assumptions made.
AI interview prep
Core dilemma
Assessing a candidate's foundational algorithmic thinking, data structure mastery, and ability to optimize under strict constraints across diverse problem types within a limited timeframe.
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 common data-structure and puzzle problems
Coding and Algorithm Problems
This interview consists of a series of independent coding and algorithm problems. You should solve them using a language of your choice, assuming typical 32/64-bit integer constraints.
1. Reverse a Singly Linked List
Given the head of a singly linked list, reverse it and return the new head. You may implement either an iterative or a recursive solution, or both.
2. Numbering on an Outward Spiral Grid
Integers are written on an infinite 2D grid starting with 1 at (0,0), then 2 at (1,0), and continuing counterclockwise in an outward square spiral (moving right, then up, then left, then down, and so on). Given integer coordinates (x, y), compute the value written at that cell. Your solution must run in O(1) time, without simulating the spiral.
3. 100 Bulbs Toggling
There are 100 light bulbs, labeled 1 through 100, all initially OFF. Person 1 toggles every bulb. Person 2 toggles bulbs 2, 4, 6, .... Person 3 toggles bulbs 3, 6, 9, ..., and this pattern continues until Person 100 toggles bulb 100. Determine which bulbs are ON at the end of this process.
4. Delete a Node with Only That Node's Pointer
You are given a pointer or reference to a specific node p within a singly linked list. You do not have access to the head pointer of the list. Delete node p from the list in O(1) time. State any required assumptions for your solution.
5. Bridge-and-Torch Scheduling
Four people need to cross a bridge at night, and they have only one torch. At most two people can cross the bridge at a time, and anyone crossing must carry the torch. The individual crossing times for the four people are 1, 2, 5, and 6 minutes. When two people cross together, the pair's crossing time is determined by the slower person's time. Find a schedule that allows everyone to cross the bridge in 13 minutes or less, or prove that it is impossible.
6. Validate a Binary Search Tree (BST)
Given the root of a binary tree, determine whether it satisfies the binary search tree property.
7. Merge Intervals
Given a list of intervals, where each interval is represented as [start, end] (inclusive), merge all overlapping intervals and return the merged list.
8. Maximum Adjacent Gap After Sorting
Given an unsorted array of integers, determine the maximum difference between two adjacent elements in the sorted version of the array. Design an algorithm that is better than O(n log n) time complexity if possible, and state any assumptions made.