Showing 21 questions
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.
#1. LRU Cache
Determine if you can construct a ransom note from the letters in a magazine. Each letter in the magazine can only be used once.
#2. Ransom Note
You are given a collection of intervals. Merge all overlapping intervals into a single interval and return the result.
#3. Merge Intervals
Given a string, repeatedly remove consecutive duplicate characters if they appear k times in a row. The goal is to return the final string after all possible removals.
#4. Remove All Adjacent Duplicates in String II
Given a number 'n', generate all possible well-formed (balanced) parentheses strings of length 2*n. For instance, if n=3, you need to create all valid combinations like '((()))', '(()())', etc.
#5. Generate Parentheses
Given a list of words, group together all the anagrams. Anagrams are words that contain the same letters rearranged.
#6. Group Anagrams
Find the k most frequent elements in a given array of numbers. Return the top k elements based on their frequency.
#7. Top K Frequent Elements
Imagine a grid of land and water. Find the largest connected area of land and return its size.
#8. Max Area of Island
You are given k sorted lists. Combine all of their elements into a single sorted list and return it.
#9. Merge k Sorted Lists
Given a grid representing land and water, count the number of distinct islands. An island is formed by connected land cells.
#10. Number of Islands
Find the longest palindromic substring within a given string. A palindromic substring reads the same forwards and backward.
#11. Longest Palindromic Substring
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.
#12. Valid Anagram
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.
#13. Search in Rotated Sorted Array
Find the longest string that is a prefix of all strings in a given array. If no common prefix exists, return an empty string.
#14. Longest Common Prefix
Determine the total number of continuous subarrays within a given array that sum up to a specific target value, k.
#15. Subarray Sum Equals K
You're given 2 eggs and N floors. Determine the minimum number of drops needed to find the critical floor where the egg breaks.
#16. Egg Drop With 2 Eggs and N Floors
Calculate a new array where each element is the product of all numbers in the original array, excluding the number at that index. Do this efficiently without using division.
#17. Product of Array Except Self
You are climbing a staircase with n steps. Find how many distinct ways you can climb to the top, given that you can climb one or two steps at a time.
#18. Climbing Stairs
Determine if a given abbreviation is valid for a given word. An abbreviation can contain digits representing the number of skipped characters.
#19. Valid Word Abbreviation
Reverse a portion of a linked list. You're given the head of the list and start/end positions; reverse only the nodes between those positions.
#20. Reverse Linked List II