Showing 43 questions
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.
#1. Best Time to Buy and Sell Stock
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.
#2. 3Sum
Imagine children standing in a circle passing a ball. Given the starting child, the number of children, and a number of passes (seconds), determine which child will have the ball after all the passes are made.
#3. Find the Child Who Has the Ball After K Seconds
Given a list of daily temperatures, find how many days you have to wait until a warmer temperature. Return a list where each element represents the waiting days for each day's temperature.
#4. Daily Temperatures
Find the length of the longest substring within a given string that contains no repeating characters. The substring must be contiguous.
#5. Longest Substring Without Repeating Characters
Find the smallest absolute difference between any two elements in a given array of numbers. Return this minimum difference.
#6. Minimum Absolute Difference
Determine the minimum capacity needed for a ship to transport packages within a given number of days. You're given the weights of the packages and must find the smallest capacity that allows shipping all packages within the day limit.
#7. Capacity To Ship Packages Within D Days
Find the number of unique paths from the top-left to the bottom-right corner of a grid, but with obstacles blocking some paths. You need to navigate the grid avoiding the obstacles.
#8. Unique Paths II
You are a robber planning to rob houses along a street. Maximize your loot, but be careful - adjacent houses have connected security systems that will trigger an alarm if you rob them both.
#9. House Robber
Find the smallest substring within a larger string that contains all the characters of a target string. You need to locate the minimum window that satisfies this condition.
#10. Minimum Window Substring
Simulate backspace operations on two strings and determine if the resulting strings are equal. Effectively, you need to compare strings after processing backspace characters.
#11. Backspace String Compare
Convert a given integer into its Roman numeral representation. You need to understand the mapping between integer values and Roman symbols to perform the conversion accurately.
#12. Integer to Roman
Imagine a rectangular brick wall. Your goal is to draw a vertical line that crosses the fewest bricks; the line can only be drawn in the spaces between bricks. Find the minimum number of bricks crossed.
#13. Brick Wall
Determine if a string containing parentheses is valid. A valid string has matching and properly nested opening and closing parentheses.
#14. Valid Parentheses
Find the minimum path sum from top to bottom in a triangle where each step moves to an adjacent number in the row below. Essentially, you need to determine the cheapest route through the triangle.
#15. Triangle
Given an array of numbers, find the index where the sum of numbers to the left equals the sum of numbers to the right. If no such index exists, return -1.
#16. Find Pivot Index
Given an array of numbers and a threshold, find the smallest divisor that ensures the sum of the divisions (ceiling) is less than or equal to the threshold. You need to efficiently search for this divisor.
#17. Find the Smallest Divisor Given a Threshold
Design a data structure that supports insertion, deletion, and random element retrieval, all in constant time on average. You'll need to handle edge cases carefully to achieve O(1) complexity.
#18. Insert Delete GetRandom O(1)
You are given an array where each element represents the maximum jump length from that position. Find the minimum number of jumps required to reach the last index.
#19. Jump Game II
Find the kth smallest value in a given Binary Search Tree. Return the node's value that holds this smallest element.
#20. Kth Smallest Element in a BST