Showing 16 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 k most frequent elements in a given array of numbers. Return the top k elements based on their frequency.
#2. Top K Frequent Elements
Find all starting indices of substring(s) in a given string that are formed by the concatenation of all words from a provided list, where each word must appear exactly once and without any intervening characters.
#3. Substring with Concatenation of All Words
Find the maximum value within each sliding window of a given size as it moves across an array.
#4. Sliding Window Maximum
Given an absolute file path (Unix style), simplify it by resolving redundant separators, directory names, and navigating back up the directory structure. Return the simplified canonical path.
#5. Simplify Path
Simulate multiplication of two non-negative integers represented as strings. Return the product, also represented as a string.
#6. Multiply Strings
Determine if a string containing parentheses and asterisks is a valid parenthesis string. The asterisk can represent a left parenthesis, a right parenthesis, or an empty string.
#7. Valid Parenthesis String
Given four numbers, determine if you can use the operations +, -, *, and / to reach the value 24. Each number must be used exactly once.
#8. 24 Game
You are given a grid with keys and locks. Find the shortest path to collect all the keys, where each key unlocks a corresponding lock.
#9. Shortest Path to Get All Keys
Simulate backspace operations on two strings and determine if the resulting strings are equal. Effectively, you need to compare strings after processing backspace characters.
#10. Backspace String Compare
Determine if a string is a palindrome after removing at most one character. Consider both left and right removals when checking for palindrome validity.
#11. Valid Palindrome II
Distribute candies to children standing in a line such that each child with a higher rating gets more candies than their neighbors. Find the minimum number of candies needed.
#12. Candy
You're given a list of asteroids, each with a size and direction (positive is right, negative is left). Figure out which asteroids will survive after all collisions happen.
#13. Asteroid Collision
Find the three numbers in a given array whose product is maximum. Return the maximum product possible from any three numbers in the array.
#14. Maximum Product of Three Numbers
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.
#15. Decode String
Find the longest subarray containing only 1s, where you are allowed to flip up to k 0s to 1s. Return the maximum length of such a subarray.
#16. Max Consecutive Ones III