Showing 141 questions
You're given a sorted array of integers and need to return a list of ranges summarizing the consecutive numbers. Each range should be represented as "a->b" if a != b, or just "a" if a == b.
#1. Summary Ranges
You're given a row of seats, some occupied and some empty. Find the best seat to maximize the distance to the nearest person.
#2. Maximize Distance to Closest Person
Find the longest contiguous subarray containing only 1s after deleting at most one element from the given binary array (containing only 0s and 1s).
#3. Longest Subarray of 1's After Deleting One Element
Compress a given string by replacing consecutive repeating characters with the character followed by the count of repetitions. If the compressed string isn't shorter, return the original.
#4. String Compression
Given a sorted array, find the k closest elements to a given value. Return the k closest elements in sorted order.
#5. Find K Closest Elements
Determine the total number of continuous subarrays within a given array that sum up to a specific target value, k.
#6. Subarray Sum Equals K
Determine if two strings are isomorphic, meaning if one string's characters can be replaced to get the other while preserving the order of characters. Essentially, check if the 'pattern' of character occurrences is the same in both strings.
#7. Isomorphic Strings
Find the length of the longest substring within a given string that contains no repeating characters. The substring must be contiguous.
#8. Longest Substring Without Repeating Characters
Determine if a string contains a permutation of another string. In other words, check if any rearrangement of the shorter string exists as a substring within the longer string.
#9. Permutation in String
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.
#10. Valid Palindrome
You are given a collection of intervals. Merge all overlapping intervals into a single interval and return the result.
#11. Merge Intervals
Given an array, rearrange it so that all zeros are moved to the end while maintaining the relative order of the non-zero elements.
#12. Move Zeroes
Design a data structure that supports insertion, deletion, and random element retrieval, all in constant time on average. You'll need to handle edge cases carefully to achieve O(1) complexity.
#13. Insert Delete GetRandom O(1)
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.
#14. Two Sum
Determine if a set of points in a 2D plane are symmetric about a vertical line. That is, check if there exists a vertical line such that for each point, there's a corresponding point reflected across it.
#15. Line Reflection
You're given a sorted array of integers. Return a new array containing the squares of each number, also sorted in non-decreasing order.
#16. Squares of a Sorted Array
Determine if a string is a palindrome after removing at most one character. Consider both left and right removals when checking for palindrome validity.
#17. Valid Palindrome II
Given a list of words, group together all the anagrams. Anagrams are words that contain the same letters rearranged.
#18. Group Anagrams
Determine if a string containing parentheses is valid. A valid string has matching and properly nested opening and closing parentheses.
#19. Valid Parentheses
Given a grid representing land and water, count the number of distinct islands. An island is formed by connected land cells.
#20. Number of Islands