Showing 28 questions
Find the longest string that is a prefix of all strings in a given array. If no common prefix exists, return an empty string.
#1. Longest Common Prefix
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.
#2. LRU Cache
Given an array and a maximum allowed difference, find the longest subarray where the most frequent element appears at least the same number of times as all other elements combined. You can change elements by at most the allowed difference amount to achieve this.
#3. Find the Longest Equal Subarray
Find the length of the longest substring within a given string that contains no repeating characters. The substring must be contiguous.
#4. Longest Substring Without Repeating Characters
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.
#5. String Compression
Find the median of two sorted arrays. The arrays can be of different sizes, and you should aim for an efficient solution.
#6. Median of Two Sorted Arrays
Traverse a binary tree level by level. Return a list of lists, where each inner list contains the nodes at a specific level.
#7. Binary Tree Level Order Traversal
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. You need to implement a stack with an additional function to efficiently get the minimum value.
#8. Min Stack
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.
#9. Two Sum
Find the k most frequently occurring words in a given list of words. Return the top k words sorted by frequency, and then alphabetically for words with the same frequency.
#10. Top K Frequent Words
Determine if a person could attend all meetings given a list of meeting time intervals. You're given start and end times for each meeting; see if any overlap.
#11. Meeting Rooms
Find the minimum sum of a path from the top-left to the bottom-right corner of a grid. You can only move down or right at each step.
#12. Minimum Path Sum
Design a data structure that supports insert, delete, and getRandom operations, all in average O(1) time. The getRandom method should return a random element from the current set of elements.
#13. Insert Delete GetRandom O(1)
Given a list of words, group together all the anagrams. Anagrams are words that contain the same letters rearranged.
#14. Group Anagrams
Implement a basic hash map data structure. You'll need to handle storing key-value pairs, retrieving values by key, and removing entries.
#15. Design HashMap
Given a string of digits, find all possible valid IP address combinations you can create by inserting dots. An IP address is valid if each segment is between 0 and 255.
#16. Restore IP Addresses
Find the maximum value within a sliding window of size k as it moves across an array. You'll need to efficiently update the maximum as the window slides.
#17. Sliding Window Maximum
You're given two sorted lists. Combine them into a single sorted list containing all elements from both original lists.
#18. Merge Two Sorted Lists
You're given a sorted array that has been rotated, and a target value. Find the index of the target value in the rotated array, or return -1 if it's not present.
#19. Search in Rotated Sorted Array
Find the longest palindromic substring within a given string. A palindromic substring reads the same forwards and backward.
#20. Longest Palindromic Substring