Showing 72 questions
Determine if a given array of numbers can be divided into two subsets with equal sums. Essentially, can you split the array so both sides add up to the same value?
#1. Partition Equal Subset Sum
Determine if removing a single element from an array can make the remaining elements strictly increasing. You need to check if it's possible to obtain a strictly increasing sequence by deleting at most one element.
#2. Remove One Element to Make the Array Strictly Increasing
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.
#3. LRU Cache
Determine if one binary tree is a subtree of another binary tree. That is, check if the structure and node values of the smaller tree exactly match a portion of the larger tree.
#4. Subtree of Another Tree
Calculate the alternating sum of digits in a given number. You'll add the first digit, subtract the second, add the third, and so on.
#5. Alternating Digit Sum
Implement a Skiplist data structure that supports efficient search, insertion, and deletion of elements. A Skiplist is a probabilistic data structure with multiple levels of linked lists.
#6. Design Skiplist
You're given an array of numbers. Pair them up to minimize the largest sum among all pairs.
#7. Minimize Maximum Pair Sum in Array
Find the longest sequence of consecutive zeros (the binary gap) between ones in the binary representation of a given positive integer.
#8. Binary Gap
Find the shortest subsequence in a string S that contains all characters of another string T in the correct order. You need to find the minimum window in S that is a subsequence of T.
#9. Minimum Window Subsequence
Given a grid representing land and water, count the number of distinct islands. An island is formed by connected land cells.
#10. Number of Islands
Traverse a given matrix in a spiral pattern, returning all elements in the order you visit them. Essentially, walk around the matrix layer by layer, adding elements to a list.
#11. Spiral Matrix
Transform one word into another, one letter at a time, using only words from a given dictionary. Find the shortest sequence of words to reach the target.
#12. Word Ladder
You're given a lock with four dials, each 0-9. Find the minimum number of turns to open the lock to a target combination, avoiding a list of dead ends.
#13. Open the Lock
Determine if it is possible to finish all courses given prerequisites. Some courses must be taken before others; can you find a valid order?
#14. Course Schedule
You are given a board of characters and a list of words. Find all the words from the list that can be formed by traversing adjacent cells on the board.
#15. Word Search II
Given an array, rearrange it so that all zeros are moved to the end while maintaining the relative order of the non-zero elements.
#16. Move Zeroes
Traverse a binary tree level by level. Return the nodes in a list, alternating the order of nodes from left to right and right to left for each level.
#17. Binary Tree Zigzag Level Order Traversal
Given a matrix, if any element is zero, set its entire row and column to zero. Do this in-place.
#18. Set Matrix Zeroes
You're given a list of courses and their prerequisites. Determine a valid order in which you can take all the courses, respecting the dependencies. If it's impossible to finish all courses, indicate that.
#19. Course Schedule II
Determine if a string containing parentheses is valid. A valid string has matching and properly nested opening and closing parentheses.
#20. Valid Parentheses