Showing 16 questions
Find the common elements present in two given arrays. Return an array containing these intersecting elements, ensuring each element appears only once.
#1. Intersection of Two Arrays
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.
#2. Text Justification
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?
#3. Word Break
Implement a multithreaded web crawler to efficiently explore and retrieve pages from a website, respecting the website's rules.
#4. Web Crawler Multithreaded
Track and query the fluctuating price of a stock. You need to efficiently find the latest price and the highest price recorded so far.
#5. Stock Price Fluctuation
You are given two binary trees. Merge them into a new binary tree where nodes at the same position are summed; if only one tree has a node in a position, use its value.
#6. Merge Two Binary Trees
You are given a sorted list of non-overlapping intervals and a new interval. Your task is to insert the new interval into the list, merging if necessary, and return the updated list of intervals.
#7. Insert Interval
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.
#8. LRU Cache
You are given k sorted lists. Combine all of their elements into a single sorted list and return it.
#9. Merge k Sorted Lists
You're given a string that represents a JSON object. Your task is to parse this string and convert it into a usable object or data structure within your programming language.
#10. Convert JSON String to Object
Find the lowest common ancestor of two nodes in a given binary tree. The lowest common ancestor is defined as the farthest node from the root that is an ancestor of both nodes.
#11. Lowest Common Ancestor of a Binary Tree
Find the maximum value within each sliding window of a given size as it moves across an array.
#12. Sliding Window Maximum
Design a hit counter that records hits and retrieves the number of hits in the past 5 minutes. You need to implement methods to record a hit and get the total hits in a sliding window.
#13. Design Hit Counter
Design a data structure that efficiently stores a set of strings and allows for prefix-based searches. Implement methods to insert strings, search for complete words, and check if any word starts with a given prefix.
#14. Implement Trie (Prefix Tree)
Design a search autocomplete system that suggests relevant sentences based on user input. You'll need to store sentences and their frequencies to provide ranked suggestions as the user types.
#15. Design Search Autocomplete System
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.
#16. Search in Rotated Sorted Array