Showing 35 questions
You are given a collection of intervals. Merge all overlapping intervals into a single interval and return the result.
#1. Merge Intervals
Find the smallest positive integer that is missing from a given array of integers. You need to do this in linear time and constant extra space.
#2. First Missing Positive
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.
#3. Meeting Rooms II
You're given a list of flight tickets, each representing a departure and arrival airport. Reconstruct the itinerary by visiting all the airports in the lexicographically smallest order, starting from "JFK".
#4. Reconstruct Itinerary
You're given an array representing weights. Implement a function to randomly pick an index from the array, where the probability of picking each index is proportional to its weight.
#5. Random Pick with Weight
Design a key-value store that supports storing values associated with timestamps. You should be able to retrieve the value for a given key at the latest timestamp less than or equal to a given time.
#6. Time Based Key-Value Store
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
You're given a list that can contain integers or other nested lists. Implement an iterator to flatten this structure and yield only the integers one by one.
#8. Flatten Nested List Iterator
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.
#9. Summary Ranges
Given an array, determine if there are any two distinct elements within a certain distance of each other that have an absolute difference less than or equal to a given threshold. Consider both index and value differences.
#10. Contains Duplicate III
Determine if there are any duplicate numbers in an array where the indices of these duplicates are within a certain distance of each other. Specifically, check if any two equal numbers exist in the array, where their indices differ by at most k.
#11. Contains Duplicate II
Implement a cache that stores values with a time-to-live (TTL). Your cache should allow setting values, retrieving values, and counting the number of unexpired keys.
#12. Cache With Time Limit
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.
#13. LRU Cache
Determine if a given word can be constructed from letters in a 2D board, where letters can be used horizontally or vertically. Each letter can only be used once in the word.
#14. Word Search
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.
#15. Course Schedule II
Determine if any value appears at least twice in an array of numbers. Return true if duplicates exist; otherwise, return false.
#16. Contains Duplicate
Find the length of the longest substring within a given string that contains no repeating characters. The substring must be contiguous.
#17. Longest Substring Without Repeating Characters
You are given a network of nodes and the time it takes to travel between them. Determine the minimum time it takes for a signal to reach all nodes, starting from a given source node.
#18. Network Delay Time
Given a list of daily temperatures, find how many days you have to wait until a warmer temperature. Return a list where each element represents the waiting days for each day's temperature.
#19. Daily Temperatures
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.
#20. Top K Frequent Words