Showing 30 questions
Design a hit counter to track the number of hits recorded in the past 5 minutes. Implement methods to record a hit and retrieve the total hits in the past 5 minutes.
#1. Design Hit Counter
Implement a Tic-Tac-Toe game where players take turns placing their marks. Design the game logic to efficiently determine the winner after each move.
#2. Design Tic-Tac-Toe
Convert an IP address and a number of addresses to a CIDR block representation. Find the smallest list of CIDR blocks that covers the specified range of IP addresses.
#3. IP to CIDR
You are a robber planning to rob houses along a street. Maximize your loot, but be careful - adjacent houses have connected security systems that will trigger an alarm if you rob them both.
#4. House Robber
You are a robber planning to rob houses along a circular street. Determine the maximum amount of money you can rob without robbing adjacent houses, considering the first and last house are neighbors.
#5. House Robber II
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
Implement a snapshot array where you can update elements and take snapshots of the array at any time. Later, you should be able to retrieve the value of an element at a specific snapshot.
#7. Snapshot Array
Find the node in a binary tree that's closest to a given starting node, where distance is measured by the number of edges to the nearest leaf node.
#8. Closest Leaf in a Binary Tree
You're given a list of two-letter words. Find the length of the longest palindrome you can build by concatenating words from the list.
#9. Longest Palindrome by Concatenating Two Letter Words
Imagine navigating a binary tree. Find the shortest path, represented as a sequence of directions ('U', 'L', 'R'), from one specific node to another.
#10. Step-By-Step Directions From a Binary Tree Node to Another
You're given a message and a limit on the length of each part. Divide the message into parts, adding a suffix like "(1/5)" to each, ensuring each part respects the length limit.
#11. Split Message Based on Limit
Find the minimum absolute difference between any two elements in an array, but only consider pairs of elements that are at least a certain distance apart in the array. This distance is given as an input to your function.
#12. Minimum Absolute Difference Between Elements With Constraint
Implement a multithreaded web crawler to efficiently explore and retrieve pages from a website, respecting the website's rules.
#13. Web Crawler Multithreaded
Given a sequence of words and a line width, format the text to fit within the specified width. You must justify the text, distributing extra spaces evenly between words.
#14. Text Justification
Imagine people entering and leaving a flower garden at different times. Given the arrival and departure times for each person, and the bloom period for each flower, determine how many flowers are in full bloom when each person is in the garden.
#15. Number of Flowers in Full Bloom
You have K sorted lists of numbers. Find the smallest range [min, max] that includes at least one number from each of the K lists.
#16. Smallest Range Covering Elements from K Lists
Design a system to count recent calls within a given timeframe. Implement a class that tracks incoming requests and returns the number of requests made in the last 3000 milliseconds.
#17. Number of Recent Calls
Find the length of the longest 'mountain' (increasing then decreasing sequence) within an array of numbers. The mountain must have at least 3 elements.
#18. Longest Mountain in Array
Find all starting indices of substrings in a string `s` that are anagrams of a given string `p`. An anagram has the same letters, rearranged.
#19. Find All Anagrams in a String
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.
#20. First Missing Positive