You are given an n x n grid, with the top-left cell at (0, 0) and the bottom-right cell at (n - 1, n - 1). A robot starts at a given position startPos = [startrow, startcol] on the grid, and a string s representing a sequence of movement instructions: ‘L’ (move left), ‘R’ (move right), ‘U’ (move up), and ‘D’ (move down). The robot can execute the instructions starting from any index i in s, but it stops if it moves off the grid or runs out of instructions. Your task is to return an array answer where answer[i] represents the number of instructions the robot can execute if it starts from the ith instruction.
You are given an array of integers. Your task is to calculate the sum of absolute differences between the index of each element and the indices of all other occurrences of the same element. For each element in the array, return the sum of intervals to all its identical elements in the array.
You are given a 2D binary grid, where ‘1’ represents a security device and ‘0’ represents an empty cell. A laser beam can be formed between two devices if they are located on two different rows and no security device is in any row between them. The task is to find the total number of laser beams that can be formed.
You are given a planet with an initial mass. There are asteroids approaching the planet, each with its own mass. The planet can destroy an asteroid if its current mass is greater than or equal to the asteroid’s mass. After destroying an asteroid, the planet’s mass increases by the asteroid’s mass. You need to determine if the planet can destroy all the asteroids by strategically choosing the order of the collisions.
You are given a linked list with an even number of nodes. Each node in the list has a twin located symmetrically from the center of the list. Specifically, the ith node is the twin of the (n-1-i)th node, where n is the total number of nodes in the list. For example, the first node is the twin of the last node, the second node is the twin of the second last node, and so on. The twin sum is defined as the sum of a node and its twin. Your task is to return the maximum twin sum of the linked list.
You are given an array of strings, where each string consists of two lowercase English letters. The task is to create the longest possible palindrome by selecting some of these strings and concatenating them in any order. Each string can be used at most once. A palindrome is a string that reads the same forward and backward. Return the length of the longest palindrome that can be created, or 0 if it’s not possible to create any palindrome.