Showing 72 questions
Given a grid representing land and water, count the number of distinct islands. An island is formed by connected land cells.
#1. Number of Islands
You are given balloons arranged in a line, each with a number. Bursting a balloon yields points based on its value and its neighbors; maximize your total points by strategically choosing the burst order.
#2. Burst Balloons
Find the length of the longest strictly increasing subsequence within a given array of numbers. A subsequence doesn't need to be contiguous, but the elements must maintain their original order.
#3. Longest Increasing Subsequence
Divide an array into two subarrays such that the absolute difference between their sums is minimized. Find the best possible split to make the subarray sums as close as possible.
#4. Partition Array Into Two Arrays to Minimize Sum Difference
Traverse a binary tree and organize its nodes based on their vertical position. Return the vertical order traversal of the tree from left to right.
#5. Vertical Order Traversal of a Binary Tree
Imagine navigating a city with regular roads and special roads offering shortcuts. Find the cheapest path from a starting point to a destination, considering both the standard road costs and the special road options.
#6. Minimum Cost of a Path With Special Roads
You are given a list of cuboids. Find the maximum height of a stack you can build by placing cuboids on top of each other, where a cuboid can only be placed on top of another if it's no larger in all three dimensions.
#7. Maximum Height by Stacking Cuboids
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.
#8. LRU Cache
You're given an array of numbers. You can either double the even numbers or halve the odd numbers. Find the minimum possible difference between the largest and smallest numbers in the array after performing these operations any number of times.
#9. Minimize Deviation in Array
You're given an array and a series of queries. Each query marks a specific element in the array. Your goal is to determine which elements are marked after processing all the queries.
#10. Mark Elements on Array by Performing Queries
Find all starting indices of substring(s) in a given string that are formed by the concatenation of all words from a provided list, where each word must appear exactly once and without any intervening characters.
#11. Substring with Concatenation of All Words
Given an array representing the height of bars, calculate how much water can be trapped between them after rain. Think about finding the maximum height to the left and right of each bar.
#12. Trapping Rain Water
Given a grid of numbers, determine the maximum width of each column. Return an array containing the widths of each column.
#13. Find the Width of Columns of a Grid
Find the largest square subgrid within a grid of 0s and 1s, such that the square's border consists entirely of 1s. Return the area of that square.
#14. Largest 1-Bordered Square
Simulate typing on a keyboard where some letters are sometimes typed in reverse. Determine the final string after taking into account these reversed segments.
#15. Faulty Keyboard
Imagine a board game where you move from the bottom right to the top left, collecting numbers. Find the maximum possible score and the number of paths to achieve that score.
#16. Number of Paths with Max Score
Pick a number between 1 and n. I'll give you hints (higher or lower) until you guess my number correctly. Minimize the number of guesses.
#17. Guess Number Higher or Lower
Design a graph data structure that allows you to add edges and calculate the shortest path between any two nodes. Implement a shortest path algorithm to efficiently find the minimum distance.
#18. Design Graph With Shortest Path Calculator
Determine the fewest operations needed to sort a given string lexicographically. Each operation involves swapping a character with the smallest character to its right.
#19. Minimum Number of Operations to Make String Sorted
Given a binary search tree and a target value, determine if there exist two nodes in the BST whose values add up to the target.
#20. Two Sum IV - Input is a BST