Showing 237 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 if any value appears at least twice in an array of numbers. Return true if duplicates exist; otherwise, return false.
#2. Contains Duplicate
Find the length of the longest substring within a given string that contains no repeating characters. The substring must be contiguous.
#3. Longest Substring Without Repeating Characters
Convert a Roman numeral string into its corresponding integer value. The input string will represent a valid Roman numeral.
#4. Roman to Integer
Find the maximum depth (number of nodes along the longest path) from the root to a leaf node in a given binary tree. Essentially, you need to determine how 'tall' the tree is.
#5. Maximum Depth of Binary Tree
You are given the head of a singly linked list. Reverse the list and return the new head.
#6. Reverse Linked List
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.
#7. Container With Most Water
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.
#8. LRU Cache
Find the median of two sorted arrays. The arrays can be of different sizes, and you should aim for an efficient solution.
#9. Median of Two Sorted Arrays
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.
#10. 3Sum
You are given two sorted integer arrays. Merge the second array into the first one, maintaining the sorted order.
#11. Merge Sorted Array
You are given a binary tree. Devise a way to convert the tree into a string representation (serialize) and then reconstruct the tree from that string (deserialize).
#12. Serialize and Deserialize Binary Tree
Given a sorted array, remove the duplicate elements in-place such that each unique element appears only once. Return the new length of the array.
#13. Remove Duplicates from Sorted Array
Determine if a given string can be segmented into a space-separated sequence of words from a dictionary. You are given a string and a dictionary of words; can you break the string down using words from the dictionary?
#14. Word Break
Determine if a given linked list contains a cycle. If a cycle exists, return true; otherwise, return false.
#15. Linked List Cycle
You are given two linked lists, each representing a non-negative integer. Add the two numbers and return the sum as a linked list.
#16. Add Two Numbers
Determine whether an integer is a palindrome. That is, it reads the same forwards and backward.
#17. Palindrome Number
You're given multiple sorted arrays. Find the maximum possible distance between any two integers picked from different arrays.
#18. Maximum Distance in Arrays
You are given a matrix and a starting cell. Return the coordinates of all cells in the matrix sorted by their Manhattan distance from the starting cell.
#19. Matrix Cells in Distance Order
You are given a square matrix representing an image. Rotate the image by 90 degrees clockwise in-place.
#20. Rotate Image