Showing 57 questions
Find all unique combinations of numbers from a given array that sum up to a specific target value. You can use the same number multiple times.
#1. Combination Sum
Given a sequence of words and a line width, format the text to fit within the specified width. You must justify the text, distributing extra spaces evenly between words.
#2. Text Justification
You're given a list of jobs with start times, end times, and profits. Find the maximum profit you can obtain by scheduling a subset of jobs that don't overlap.
#3. Maximum Profit in Job Scheduling
Find pairs of words from a given list that, when concatenated in either order, form a palindrome. Return the indices of these pairs.
#4. Palindrome Pairs
You are given a 2D vector of integers. Implement an iterator to flatten it into a 1D vector, allowing you to access elements sequentially.
#5. Flatten 2D Vector
You're given a list of regions organized hierarchically. Find the smallest region that is an ancestor of two given regions in the hierarchy.
#6. Smallest Common Region
Imagine pouring water onto a terrain represented by an array of heights. Simulate how the water distributes itself, considering the terrain's shape and gravity, to determine the final water levels after pouring a given amount.
#7. Pour Water
Find the cheapest price to fly from a source to a destination with at most K stops. You're given a list of flights with prices and need to determine the optimal route within the stop limit.
#8. Cheapest Flights Within K Stops
You are given a sorted list of words from an alien language and need to deduce the order of the letters in that language. Determine the alien alphabet order based on the given word sequence.
#9. Alien Dictionary
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.
#10. Trapping Rain Water
Rearrange tiles in a sliding puzzle to reach a target configuration. Find the minimum number of moves required to solve the puzzle.
#11. Sliding Puzzle
You're given boxes containing candies, some locked initially. Determine the maximum number of candies you can collect by strategically using keys found in open boxes to unlock others.
#12. Maximum Candies You Can Get from Boxes
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.
#13. Minimum Window Substring
Simulate a simple bank system that supports basic operations like deposit, withdraw, and check balance for different accounts. You will implement methods to handle these transactions and ensure validity based on account balances and existence.
#14. Simple Bank System
Determine the node at which two singly linked lists intersect. Return null if the lists do not intersect.
#15. Intersection of Two Linked Lists
You're given the schedules of multiple employees, each consisting of intervals of busy time. Find the common free time intervals for all the employees.
#16. Employee Free Time
Determine if there are any duplicate numbers in an array where the indices of these duplicates are within a certain distance of each other. Specifically, check if any two equal numbers exist in the array, where their indices differ by at most k.
#17. Contains Duplicate II
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.
#18. Two Sum
You are given a grid with keys and locks. Find the shortest path to collect all the keys, where each key unlocks a corresponding lock.
#19. Shortest Path to Get All Keys
Implement a basic calculator to evaluate a simple expression string. The expression can contain non-negative integers, '+', '-', '*', '/' operators, and spaces; integer division should truncate toward zero.
#20. Basic Calculator II