Showing 270 questions
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.
#1. Trapping Rain Water
Find the minimum sum of a path from the top-left to the bottom-right corner of a grid. You can only move down or right at each step.
#2. Minimum Path Sum
Find the minimum element in a sorted array that has been rotated. The array was initially sorted, but some portion of it has been shifted to the beginning.
#3. Find Minimum in Rotated Sorted Array
You're given houses along a street and need to place mailboxes to minimize the total distance residents walk. Determine the optimal locations for a given number of mailboxes.
#4. Allocate Mailboxes
Given a fraction represented by its numerator and denominator, convert it to a string representation, handling potential recurring decimal parts. Identify and enclose the repeating part within parentheses.
#5. Fraction to Recurring Decimal
Calculate the average of the top five scores for each student given a list of their scores. Return the result as a list of student IDs and their corresponding top-five average.
#6. High Five
Find the first character in a string that appears only once. If no such character exists, return a specified value.
#7. First Unique Character in a String
Find the length of the longest substring within a given string that contains no repeating characters. The substring must be contiguous.
#8. Longest Substring Without Repeating Characters
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.
#9. LRU Cache
Find the median of two sorted arrays. The arrays can be of different sizes, and you should aim for an efficient solution.
#10. Median of Two Sorted Arrays
Given a list of words, group together all the anagrams. Anagrams are words that contain the same letters rearranged.
#11. Group Anagrams
Construct Pascal's Triangle up to a given number of rows. Each number in Pascal's Triangle is the sum of the two numbers directly above it.
#12. Pascal's Triangle
You're given an array that's supposedly a doubled version of another array. Your task is to reconstruct the original array from this doubled array, if possible.
#13. Find Original Array From Doubled Array
A robot follows a sequence of instructions (move and rotate). Determine if the robot ends up back at its starting point, or if it's trapped in a repeating circular path.
#14. Robot Bounded In Circle
Starting from (0, 0), can you reach a target point (tx, ty) by repeatedly applying the transformation (x, y) -> (x, x+y) or (x, y) -> (x+y, y)? Determine if it's possible.
#15. Reaching Points
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.
#16. Best Time to Buy and Sell Stock
Imagine people in a circle, eliminating every kth person. Determine who is the last person remaining after this process.
#17. Find the Winner of the Circular Game
Given a grid representing land and water, count the number of distinct islands. An island is formed by connected land cells.
#18. Number of Islands
Compress a given string by replacing consecutive repeating characters with the character followed by the count of repetitions. If the compressed string isn't shorter, return the original.
#19. String Compression
Simulate backspace operations on two strings and determine if the resulting strings are equal. Effectively, you need to compare strings after processing backspace characters.
#20. Backspace String Compare