Showing 48 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
You're given lists of player scores and ages. Find the highest possible total score of a team, but avoid conflicts where an older player has a lower score than a younger player on the team.
#2. Best Team With No Conflicts
You are given an array representing the prefix XOR of another array. Your task is to reconstruct and return the original array from its prefix XOR representation.
#3. Find The Original Array of Prefix Xor
You are given chips at various positions. Find the minimum cost to move all the chips to the same position, where moving a chip two positions costs nothing and moving one position costs one unit.
#4. Minimum Cost to Move Chips to The Same Position
You are given a sequence of obstacle heights. For each position in the sequence, find the length of the longest obstacle course ending at that position that is both non-decreasing and includes that obstacle.
#5. Find the Longest Valid Obstacle Course at Each Position
You are given a list of employees and their task durations. Find the ID of the employee who worked on the longest task.
#6. The Employee That Worked on the Longest Task
Given a set of points on a 2D plane, find the minimum number of straight lines needed to cover all the points. Each line can cover multiple points.
#7. Minimum Number of Lines to Cover Points
Determine if an array contains two subarrays with the same sum. Return true if such subarrays exist, and false otherwise.
#8. Find Subarrays With Equal Sum
You are given an array and two numbers, minK and maxK. Find the number of subarrays where minK and maxK are the minimum and maximum values within that subarray, respectively.
#9. Count Subarrays With Fixed Bounds
You are given a collection of intervals. Merge all overlapping intervals into a single interval and return the result.
#10. Merge Intervals
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.
#11. Two Sum
You're given an array containing only 0s, 1s, and 2s. Sort the array in place so that elements of the same value are grouped together.
#12. Sort Colors
Find the length of the longest substring within a given string that contains no repeating characters. The substring must be contiguous.
#13. Longest Substring Without Repeating Characters
Find the kth largest element in an unsorted array. Note that it is the kth largest element in sorted order, not the kth distinct element.
#14. Kth Largest Element in an Array
Find the smallest positive integer that is missing from a given array of integers. You need to do this in linear time and constant extra space.
#15. First Missing Positive
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.
#16. LRU Cache
You are given an array where each element represents your maximum jump length at that position. Determine if you can reach the last index starting from the first index.
#17. Jump Game
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.
#18. 3Sum
Determine the total number of continuous subarrays within a given array that sum up to a specific target value, k.
#19. Subarray Sum Equals K
Find the maximum length of a contiguous subarray with an equal number of 0 and 1. You are given a binary array.
#20. Contiguous Array