Showing 41 questions
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.
#1. Container With Most Water
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.
#2. Two Sum
You are given a graph where each node has a value. Find the maximum possible 'quality' of a path that starts and ends at node 0, visiting any node at most once per path, given a maximum time limit for the path.
#3. Maximum Path Quality of a Graph
You're given a classroom layout where students can't sit next to each other (horizontally or diagonally). Find the maximum number of students that can take the exam.
#4. Maximum Students Taking Exam
You're given a number of initially infected people and a length of days. Calculate the total number of distinct ways the infection can spread each day, given some constraints on who can infect whom.
#5. Count the Number of Infection Sequences
Find the number of increasing quadruplets (i, j, k, l) in an array, where i < j < k < l and nums[i] < nums[k] < nums[j] < nums[l]. Count how many such quadruplets exist within the input array.
#6. Count Increasing Quadruplets
Find the longest string that is a prefix of all strings in a given array. If no common prefix exists, return an empty string.
#7. Longest Common Prefix
Determine if a string containing parentheses is valid. A valid string has matching and properly nested opening and closing parentheses.
#8. Valid Parentheses
Given a grid representing land and water, count the number of distinct islands. An island is formed by connected land cells.
#9. Number of Islands
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
You are given the head of a singly linked list. Reverse the list and return the new head.
#11. Reverse Linked List
Find the area of the largest square that can be formed within a binary matrix containing only 1s and 0s, where the square's sides consist only of 1s.
#12. Maximal Square
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.
#13. Best Time to Buy and Sell Stock
You are given a collection of intervals. Merge all overlapping intervals into a single interval and return the result.
#14. Merge Intervals
Find the length of the longest substring within a given string that contains no repeating characters. The substring must be contiguous.
#15. Longest Substring Without Repeating Characters
Determine if a given string is a palindrome, considering only alphanumeric characters and ignoring cases. Essentially, check if the string reads the same forwards and backward after removing non-alphanumeric characters and converting to lowercase.
#16. Valid Palindrome
Determine if a string can be rotated to match another string. You're essentially checking if one string is a shifted version of the other.
#17. Rotate String
Find the index of the leftmost column in a binary matrix that contains at least one 1. The matrix is sorted in non-decreasing order in each row.
#18. Leftmost Column with at Least a One
Find the longest palindromic substring within a given string. A palindromic substring reads the same forwards and backward.
#19. Longest Palindromic Substring
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.
#20. Longest Consecutive Sequence