Showing 104 questions
You're given two arrays. Construct the longest possible non-decreasing subarray by picking elements from either array at each index.
#1. Longest Non-decreasing Subarray From Two Arrays
Find the minimum number of moves a knight needs to reach a target position on an infinite chessboard, starting from (0, 0).
#2. Minimum Knight Moves
Find the maximum sum of any path in a binary tree, where a path can start and end at any node. The path must contain at least one node.
#3. Binary Tree Maximum Path Sum
Find the maximum value within a sliding window of size k as it moves across an array. You'll need to efficiently update the maximum as the window slides.
#4. Sliding Window Maximum
Find the number of palindromic substrings within a given string. Consider each single character and repeated characters as a substring.
#5. Palindromic Substrings
The problem asks you to find the total number of distinct palindromic subsequences within a given string. Remember that subsequences don't have to be contiguous.
#6. Count Palindromic Subsequences
You're given a list of numbers. By deleting a number, you earn its value, but you must also delete all numbers one less and one greater than it. Maximize the total earned value.
#7. Delete and Earn
You're given two arrays that contain zeros. Replace the zeros in each array with positive integers to maximize the chance of making the two arrays have equal sums. Find the minimum equal sum achievable or determine if it's impossible.
#8. Minimum Equal Sum of Two Arrays After Replacing Zeros
You're given a list of numbers. Determine the minimum number of operations to make all numbers non-positive by either subtracting or dividing them by a given value.
#9. Minimum Operations to Make Numbers Non-positive
Design and implement a Least Frequently Used (LFU) cache. The cache should allow you to get and put key-value pairs, evicting the least frequently used key when the cache is full.
#10. LFU Cache
You're given a set of spells with damage and cost. Choose the subset of spells that maximizes your total damage, staying within a given mana limit.
#11. Maximum Total Damage With Spell Casting
You're given the costs of traveling between cities on a train line, with options to use regular tickets or purchase a travel pass for unlimited rides. Find the minimum total cost to travel to the last city.
#12. Minimum Costs Using the Train Line
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
You're given a set of delivery locations. Find the best spot to build a service center that minimizes the total distance to all locations.
#14. Best Position for a Service Centre
Find the longest common subarray between two given arrays of integers. Return the length of this maximal repeated subarray.
#15. Maximum Length of Repeated Subarray
You are given a matrix and a sequence of integers. Determine the index of the first integer in the sequence that results in a fully painted row or column in the matrix.
#16. First Completely Painted Row or Column
You are given equations represented by pairs of variables and their corresponding values. Your task is to evaluate queries based on these equations, determining the value of expressions if possible, or returning -1.0 if not.
#17. Evaluate Division
Given an array of numbers where one number appears more than once, find the duplicate number. You should do this without modifying the original array and using only constant extra space.
#18. Find the Duplicate Number
You are given a binary tree. Devise a way to convert the tree into a string representation (serialize) and then reconstruct the tree from that string (deserialize).
#19. Serialize and Deserialize Binary Tree
You are given a collection of intervals. Merge all overlapping intervals into a single interval and return the result.
#20. Merge Intervals