Showing 141 questions
You're given a pile of stones with different weights. In each turn, you smash the two heaviest stones together, and the goal is to find the weight of the last remaining stone (or zero if no stone remains).
#1. Last Stone Weight
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.
#2. LRU Cache
Given a list of words, group together all the anagrams. Anagrams are words that contain the same letters rearranged.
#3. Group Anagrams
Find the minimum number of operations to reduce a given positive integer to 0. You can either subtract a power of 2 or add a power of 2 in each operation.
#4. Minimum Operations to Reduce an Integer to 0
A special binary string has equal numbers of 0s and 1s, and any prefix has at least as many 1s as 0s. You need to recursively make the lexicographically largest special string possible from a given special binary string.
#5. Special Binary String
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.
#6. Best Time to Buy and Sell Stock
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 linked lists, each representing a non-negative integer. Add the two numbers and return the sum as a linked list.
#8. Add Two Numbers
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.
#9. Two Sum
Find the contiguous subarray within a given array of numbers which has the largest sum. Return the sum of this subarray.
#10. Maximum Subarray
You're given a sorted array that has been rotated, and a target value. Find the index of the target value in the rotated array, or return -1 if it's not present.
#11. Search in Rotated Sorted Array
Imagine you're standing at a fixed location looking at points on a 2D plane. Determine the maximum number of points you can see within a given field of view by rotating your position.
#12. Maximum Number of Visible Points
Given a grid representing land and water, count the number of distinct islands. An island is formed by connected land cells.
#13. Number of Islands
You're given an integer; reverse the order of its bits. Treat the integer as an unsigned 32-bit number.
#14. Reverse Bits
Given an array of numbers, rearrange it to maximize the number of indices where array[i] < rearranged_array[i]. Essentially, you want to maximize how many numbers in the array can be replaced by a strictly larger number from within the same array.
#15. Maximize Greatness of an Array
Determine if a string containing parentheses is valid. A valid string has matching and properly nested opening and closing parentheses.
#16. Valid Parentheses
You're given an array of numbers from 0 to n, with one number missing. Find the missing number within the array.
#17. Missing Number
Calculate the dot product of two sparse vectors. You'll need to efficiently handle vectors with many zero values.
#18. Dot Product of Two Sparse Vectors
You're given a linked list where each node has a regular 'next' pointer and a 'random' pointer. Create a deep copy of this list, preserving both the next and random pointer relationships.
#19. Copy List with Random Pointer
You are given k sorted lists. Combine all of their elements into a single sorted list and return it.
#20. Merge k Sorted Lists