Showing 1720 questions
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.
#1. Two Sum
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.
#2. Best Time to Buy and Sell Stock
Rearrange the characters in a given string such that no two adjacent characters are the same. If such an arrangement is possible, return it; otherwise, return an empty string.
#3. Reorganize String
Given a grid representing land and water, count the number of distinct islands. An island is formed by connected land cells.
#4. Number of Islands
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.
#5. LRU Cache
Given an array and a limit on the subarray size, find the maximum frequency of any element after performing an operation to make all elements in one subarray equal.
#6. Maximum Frequency After Subarray Operation
Find the longest palindromic substring within a given string. A palindromic substring reads the same forwards and backward.
#7. Longest Palindromic Substring
You're given a set of points (x, y). Your goal is to find three distinct x-values such that the sum of their corresponding y-values is maximized. Return this maximum sum.
#8. Maximize Y‑Sum by Picking a Triplet of Distinct X‑Values
You are given two linked lists, each representing a non-negative integer. Add the two numbers and return the sum as a linked list.
#9. Add Two Numbers
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
Given a list of words, group together all the anagrams. Anagrams are words that contain the same letters rearranged.
#11. Group Anagrams
Koko wants to eat all the bananas in some piles within a certain time. Find the minimum eating speed that allows her to finish on time.
#12. Koko Eating Bananas
Given a sorted array, find the first and last position of a given target value. If the target is not found, return [-1, -1].
#13. Find First and Last Position of Element in Sorted Array
Find the length of the longest substring within a given string that contains no repeating characters. The substring must be contiguous.
#14. Longest Substring Without Repeating Characters
Find the k most frequent elements in a given array of numbers. Return the top k elements based on their frequency.
#15. Top K Frequent Elements
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.
#16. Jump Game II
You are given the head of a singly linked list. Reverse the list and return the new head.
#17. Reverse Linked List
You are given a collection of intervals. Merge all overlapping intervals into a single interval and return the result.
#18. Merge Intervals
Find the median of two sorted arrays. The arrays can be of different sizes, and you should aim for an efficient solution.
#19. Median of Two Sorted Arrays
Distribute candies to children standing in a line such that each child with a higher rating gets more candies than their neighbors. Find the minimum number of candies needed.
#20. Candy