Showing 50 questions
Find the largest rectangular area that can fit within a histogram defined by an array of bar heights. You are given an array representing the height of bars, where each bar has a width of 1.
#1. Largest Rectangle in Histogram
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
The problem involves decoding a string that follows a specific encoding rule: k[encoded_string], where the encoded_string inside the square brackets is repeated exactly k times. Your task is to decode the string and return the decoded string.
#3. Decode String
Given a set of distinct integers, your task is to generate all possible subsets (the power set). The solution should not contain duplicate subsets.
#4. Subsets
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?
#5. Word Break
Design and implement a Least Frequently Used (LFU) cache. The cache should allow you to get and put key-value pairs, evicting the least frequently used key when the cache is full.
#6. LFU Cache
Find the longest substring within a given string that contains at most K distinct characters. You need to determine the length of this substring.
#7. Longest Substring with At Most K Distinct Characters
Design a data structure to track ranges of numbers and efficiently add, remove, or query if a number is covered by any of the tracked ranges.
#8. Range Module
Given a binary search tree and a target value, split the tree into two BSTs. One BST should contain nodes with values less than or equal to the target, and the other should contain nodes with values greater than the target.
#9. Split BST
Given an array of numbers, find the index where the sum of numbers to the left equals the sum of numbers to the right. If no such index exists, return -1.
#10. Find Pivot Index
Determine if it is possible to finish all courses given prerequisites. Some courses must be taken before others; can you find a valid order?
#11. Course Schedule
Implement an in-memory file system with basic operations like creating directories, adding files, and listing contents. The file system should support path-based navigation.
#12. Design In-Memory File System
Find the number of unique paths from the top-left to the bottom-right corner of a grid, but with obstacles blocking some paths. You need to navigate the grid avoiding the obstacles.
#13. Unique Paths II
Find the longest substring that appears more than once in a given string. Overlapping occurrences are allowed.
#14. Longest Repeating Substring
Imagine two islands represented by ones in a grid of zeros and ones. Find the shortest path to connect the two islands by changing zeros to ones.
#15. Shortest Bridge
Find the number of unique paths from the top-left corner to the bottom-right corner of a grid, moving only down or right.
#16. Unique Paths
Determine if a group of people can be divided into two sets such that no two people who dislike each other are in the same set. You're given a list of dislikes; can you split the group?
#17. Possible Bipartition
Determine if an input string matches a given regular expression that supports '.' and '*' characters. The '.' matches any single character, and '*' matches zero or more occurrences of the preceding element.
#18. Regular Expression Matching
Find the longest substring that appears at least twice in a given string. The occurrences may overlap.
#19. Longest Duplicate Substring
Imagine you're buying items and have special offers that combine multiple items for a cheaper price. Your goal is to find the minimum cost to purchase a specific list of items, using a combination of individual prices and special offers.
#20. Shopping Offers