79 data structures and algorithms questions79 Interview Questions
Find all unique triplets in an array that sum to zero. You'll need to consider the potential for duplicate numbers and avoid duplicate triplets in your solution.
#1. 3Sum
Determine if a binary tree is height-balanced. A height-balanced tree is defined as one where the difference in height between the left and right subtrees of every node is no more than 1.
#2. Balanced Binary Tree
Find the length of the longest diagonal segment in a matrix that forms a V-shape. A V-shape is defined by monotonically decreasing values followed by monotonically increasing values along the diagonal.
#3. Length of Longest V-Shaped Diagonal Segment
Find two numbers in a given array that add up to a specific target value, and return their indices. Essentially, you need to efficiently locate the pair that satisfies the sum requirement.
#4. Two Sum
Determine if an array can be split into two non-empty subarrays with equal sums. Return true if such a split is possible, and false otherwise.
#5. Split the Array
Simulate a box tilting to the right, causing stones to fall until they hit obstacles or the floor. Re-arrange the characters in a given grid to reflect the resulting state of the box.
#6. Rotating the Box
Find the length of the longest substring within a given string that contains no repeating characters. The substring must be contiguous.
#7. Longest Substring Without Repeating Characters
You are given two arrays: numbers to insert and their corresponding indices. Construct a target array by inserting each number at its specified index.
#8. Create Target Array in the Given Order
You're given daily stock prices. Find the maximum profit you can make by buying and selling the stock once. You must buy before you sell.
#9. Best Time to Buy and Sell Stock
Given a list of words, group together all the anagrams. Anagrams are words that contain the same letters rearranged.
#10. Group Anagrams
You're given a list of events with start and end times. Determine the maximum number of events you can attend if you can only attend one event at a time.
#11. Maximum Number of Events That Can Be Attended
Imagine removing each node in a tree and calculating a score based on the sizes of the resulting subtrees. Your goal is to count how many nodes achieve the highest possible score.
#12. Count Nodes With the Highest Score
Two players take turns subtracting divisors from a given number. Determine if the first player can win if both players play optimally.
#13. Divisor Game
You are given a matrix of characters and a pattern string. Determine if the pattern can be found in the matrix by traversing adjacent cells in a row-major order.
#14. Match Alphanumerical Pattern in Matrix I
Find the maximum distance between two houses in an array that have different colors. The distance is defined as the absolute difference of their indices.
#15. Two Furthest Houses With Different Colors
You are given an array of strings. Calculate the difference between the ASCII values of consecutive characters in each string. Identify the string with a unique difference array and return it.
#16. Odd String Difference
You're given the time it takes to plant and grow each flower. Determine the earliest day on which all flowers can be in full bloom.
#17. Earliest Possible Day of Full Bloom
You are given a grid and a series of queries to place blocks of varying sizes. Determine if each block placement is valid given existing blocks and the grid boundaries.
#18. Block Placement Queries
Design a data structure that acts as a Least Recently Used (LRU) cache. Implement methods to get and put key-value pairs, evicting the least recently used entry when the cache is full.
#19. LRU Cache
Find the longest string that is a prefix of all strings in a given array. If no common prefix exists, return an empty string.
#20. Longest Common Prefix