Showing 27 questions
You are given an array of integers. Determine if you can split the array into two non-empty subarrays such that the products of the numbers in each subarray are coprime (no common factors other than 1).
#1. Split the Array to Make Coprime Products
Calculate all possible subsequence sums from a given array of numbers. Return the bitwise OR of all those sums.
#2. Bitwise OR of All Subsequence Sums
Imagine a long corridor with plants and seats. Find the number of ways to divide the corridor into sections, ensuring each section has exactly two plants.
#3. Number of Ways to Divide a Long Corridor
Find the shortest cycle (path that starts and ends at the same node) in a given graph. Return the length of this shortest cycle.
#4. Shortest Cycle in a Graph
You are given a list of shops, each having some items with associated prices. Maximize your total spending by strategically buying one item from each shop, considering a spending coefficient that increases with each purchase.
#5. Maximum Spending After Buying Items
Imagine you only know the differences between adjacent numbers in a secret sequence. Given these differences and a range, count how many valid hidden sequences could exist within that range.
#6. Count the Hidden Sequences
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.
#7. First Missing Positive
You're given a list of worker costs and need to hire exactly K workers. Determine the minimum total cost to hire these workers by strategically selecting them from the cheapest available at either end of the list.
#8. Total Cost to Hire K Workers
Find the contiguous subarray within a given array of numbers which has the largest sum. Return the sum of this subarray.
#9. Maximum Subarray
Determine if a word matches a given pattern, where a match means there's a one-to-one mapping between letters in the word and the pattern. You need to find all words from a list that match the provided pattern.
#10. Find and Replace Pattern
You're given an array where every number appears twice, except for two numbers that appear only once. Find those two unique numbers.
#11. Single Number III
Find all unique triplets in an array that sum to zero. You'll need to consider the potential for duplicate numbers and avoid duplicate triplets in your solution.
#12. 3Sum
Find the number of unique paths from the top-left to the bottom-right corner of a grid, but with obstacles blocking some paths. You need to navigate the grid avoiding the obstacles.
#13. Unique Paths II
Find all unique combinations of numbers from a given array that sum up to a target value. Each number in the array can only be used once in each combination.
#14. Combination Sum II
Determine if a given sequence of moves in a 2D plane causes the path to cross itself. The moves represent distances in the order north, west, south, and east.
#15. Self Crossing
Find two numbers in a sorted array that add up to a specific target value. Return the indices of these two numbers.
#16. Two Sum II - Input Array Is Sorted
Find the length of the longest substring within a given string that contains no repeating characters. The substring must be contiguous.
#17. Longest Substring Without Repeating Characters
You are given an array where each element represents the maximum jump length from that position. Find the minimum number of jumps required to reach the last index.
#18. Jump Game II
Design and implement a Least Frequently Used (LFU) cache. The cache should efficiently store key-value pairs, evicting the least frequently used items when it reaches capacity.
#19. LFU Cache
You're given a sorted array where every element appears twice, except for one element that appears only once. Find and return this single, unique element.
#20. Single Element in a Sorted Array