Showing 110 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
Find the smallest substring within a larger string that contains all the characters of a target string. You need to locate the minimum window that satisfies this condition.
#2. Minimum Window Substring
Transform one word into another, one letter at a time, using only words from a given dictionary. Find the shortest sequence of words to reach the target.
#3. Word Ladder
You are given a list of meeting time intervals. Determine the minimum number of conference rooms required to accommodate all the meetings without any overlap.
#4. Meeting Rooms II
You're given a grid representing land and water. Change one water cell to land to maximize the size of the largest connected land area (island) and return that maximum size.
#5. Making A Large Island
Design a system to store and retrieve logs based on different granularities (year, month, day, etc.). Implement methods to put logs and retrieve logs within a specified time range and granularity.
#6. Design Log Storage System
Given a grid representing land and water, count the number of distinct islands. An island is formed by connected land cells.
#7. Number of Islands
You're given a list of courses and their prerequisites. Determine a valid order in which you can take all the courses, respecting the dependencies. If it's impossible to finish all courses, indicate that.
#8. Course Schedule II
Imagine a grid of land and water representing islands. Find the number of distinct island shapes, considering rotations and reflections as the same shape.
#9. Number of Distinct Islands
Given a string and a dictionary of words, find all possible ways to break the string into space-separated words from the dictionary. Return the list of these valid sentences.
#10. Word Break II
Imagine you're planning a trip using a network of bus routes. Given a set of routes and start/end locations, find the fewest number of buses you must take to reach your destination.
#11. Bus Routes
Determine if two strings are considered to be one edit distance apart. An edit can be an insertion, deletion, or replacement of a single character.
#12. One Edit Distance
Determine if a given 9x9 Sudoku board is valid. Check if each row, column, and 3x3 subgrid contains the digits 1-9 without repetition.
#13. Valid Sudoku
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.
#14. Min Stack
You are given a sorted list of words from an alien language and need to deduce the order of the letters in that language. Determine the alien alphabet order based on the given word sequence.
#15. Alien Dictionary
Find all unique combinations of numbers from a given array that sum up to a specific target value. You can use the same number multiple times.
#16. Combination Sum
Given a string of digits, remove *k* digits to obtain the smallest possible number. You need to determine which digits to remove to minimize the resulting number.
#17. Remove K Digits
You are given the head of a singly linked list. Reverse the list and return the new head.
#18. Reverse Linked List
Simulate the Game of Life, updating the state of a board based on the rules of cell survival and death in each generation. Modify the board in place to represent the next generation.
#19. Game of Life
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.
#20. String Compression