Showing 66 questions
Find the longest path in a matrix where each step increases in value. You can only move up, down, left, or right.
#1. Longest Increasing Path in a Matrix
You are planning a meeting and need to invite the maximum number of employees. Employees have preferences for who they want to sit next to; find the largest group of employees who can be seated such that everyone is happy with their neighbors.
#2. Maximum Employees to Be Invited to a Meeting
Find the best pair of sightseeing spots in an array to maximize a score calculated from their values and distance. The score is the sum of the two spots' values minus the distance between them.
#3. Best Sightseeing Pair
Determine if a string can be made empty by repeatedly removing occurrences of the substring "abc". In essence, check if the string is formed by validly inserting "abc" sequences.
#4. Check If Word Is Valid After Substitutions
You need to deliver boxes from a storage area to different ports. Optimize the delivery schedule to minimize the cost of traveling between ports, grouping boxes destined for the same port together.
#5. Delivering Boxes from Storage to Ports
Design a data structure to efficiently determine if a given element is the majority element (appears more than half the time) within specified subarrays of an input array. The queries should be handled online.
#6. Online Majority Element In Subarray
A bookstore owner is grumpy some days, affecting customer happiness. Maximize happy customers by strategically using the owner's ability to be not grumpy for a limited time.
#7. Grumpy Bookstore Owner
You're given the processing times for processors and tasks. Assign each task to a processor to minimize the overall completion time, considering each processor can handle tasks in batches.
#8. Minimum Processing Time
Calculate how many car fleets will arrive at a destination given their starting positions and speeds. Cars form a fleet if they meet at the same position before reaching the destination.
#9. Car Fleet
You're given a decimal number 'n'. Find the minimum number of deci-binary numbers (numbers consisting only of 0s and 1s) that sum up to 'n'.
#10. Partitioning Into Minimum Number Of Deci-Binary Numbers
Find the maximum sum of an hourglass shape within a 2D array. The hourglass consists of 7 cells in a specific pattern.
#11. Maximum Sum of an Hourglass
You start with a number on a calculator and want to reach a target number. You can only double the current number or subtract one. Find the minimum number of operations to reach the target.
#12. Broken Calculator
Find the length of the longest substring containing only one character, allowing for one swap of a different character to achieve a longer repetition. Determine the maximum possible length after performing at most one such swap.
#13. Swap For Longest Repeated Character Substring
Determine if a given 2D grid of characters contains a cycle, where a cycle is a path of the same character that visits the same cell more than once. The path can only move up, down, left, or right.
#14. Detect Cycles in 2D Grid
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.
#15. LRU Cache
You are given a collection of intervals. Merge all overlapping intervals into a single interval and return the result.
#16. Merge Intervals
Imagine a rectangular island where water can flow from each cell to adjacent cells with equal or lower height. Determine which cells can flow to both the Pacific and Atlantic oceans.
#17. Pacific Atlantic Water Flow
Determine if an array contains an increasing subsequence of length 3. More formally, find if there exist indices i, j, k such that arr[i] < arr[j] < arr[k] where i < j < k.
#18. Increasing Triplet Subsequence
You are given a grid of oranges, some fresh, some rotten. Rotten oranges contaminate adjacent fresh oranges; find the minimum time until all oranges are rotten.
#19. Rotting Oranges
Given a list of words, group together all the anagrams. Anagrams are words that contain the same letters rearranged.
#20. Group Anagrams