You are given an array of positive integers. Compute all possible subarray sums, sort them in non-decreasing order, and return the sum of elements from index left to right in the sorted array modulo 10^9 + 7.
You are given n baskets with distinct positions, and m balls to place in them. The magnetic force between two balls at positions x and y is |x - y|. The goal is to place the balls into baskets such that the minimum magnetic force between any two balls is maximized.
You are given a permutation of integers from 1 to n, where each integer represents a position in a binary string of size n that is initially filled with zeros. At each step, you will flip the bit at the position specified by the current element of the array. You are also given an integer m, and your task is to determine the latest step at which there exists a contiguous substring of exactly m ones in the binary string.
You are a hiker navigating a terrain represented by a 2D grid of heights. Your goal is to find the path from the top-left corner to the bottom-right corner that minimizes the maximum height difference between any two consecutive cells.
You are given an inventory of different colored balls. The customer wants to buy a specific number of balls, and each ball has a value based on how many of that color are still available. Calculate the maximum total value you can obtain after fulfilling the customer’s order. The result should be returned modulo 10^9 + 7.
You are given an array of integers nums and an integer x. In each operation, you can either remove the leftmost or rightmost element from the array and subtract its value from x. The task is to determine the minimum number of operations required to reduce x to exactly 0, or return -1 if it’s not possible.