Showing 1919 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
Determine whether an integer is a palindrome. That is, it reads the same forwards and backward.
#2. Palindrome Number
You are given two linked lists, each representing a non-negative integer. Add the two numbers and return the sum as a linked list.
#3. Add Two Numbers
Divide an array into subarrays and maximize the sum of the GCDs of each subarray. Find the maximum achievable score by optimally splitting the array.
#4. Maximize Subarray GCD Score
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. These consecutive numbers do not need to be adjacent in the original array.
#5. Longest Consecutive Sequence
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
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.
#7. Candy
Find the median of two sorted arrays. The arrays can be of different sizes, and you should aim for an efficient solution.
#8. Median of Two Sorted Arrays
You are given a collection of intervals. Merge all overlapping intervals into a single interval and return the result.
#9. Merge Intervals
Find the longest string that is a prefix of all strings in a given array. If no common prefix exists, return an empty string.
#10. Longest Common Prefix
Convert a Roman numeral string into its corresponding integer value. The input string will represent a valid Roman numeral.
#11. Roman to Integer
Find the k-th smallest integer in lexicographical order among all integers from 1 to n. Consider "lexicographical order" as the order you'd find the numbers in a dictionary.
#12. K-th Smallest in Lexicographical Order
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.
#13. 3Sum
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
Convert a given string into a zigzag pattern with a specified number of rows. Then read the characters row by row to return the converted string.
#15. Zigzag Conversion
Find a peak element in an array, where a peak is greater than its neighbors. You only need to return the index of any one peak element if multiple exist.
#16. Find Peak Element
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.
#17. Trapping Rain Water
You are given an array representing the heights of vertical lines. Find two lines that, together with the x-axis, form a container that holds the most water.
#18. Container With Most Water
Determine if a string containing parentheses is valid. A valid string has matching and properly nested opening and closing parentheses.
#19. Valid Parentheses
Determine if two strings are anagrams of each other, meaning they contain the same characters in a different order. You need to check if one string can be rearranged to form the other.
#20. Valid Anagram