Given an integer array ’nums’ containing ’n’ integers, you are tasked with calculating the beauty of each subarray of size ‘k’. The beauty of a subarray is defined as the xth smallest negative integer in the subarray if it exists, or 0 if there are fewer than ‘x’ negative integers.
You are given an array of positive integers ’nums’. You can perform an operation on this array where you select two consecutive elements and replace one of them with the gcd (greatest common divisor) of the two elements. The goal is to make all elements of the array equal to 1 using the minimum number of operations. If it’s impossible to make all elements equal to 1, return -1.
You are given a 0-indexed array of positive integers ’nums’ and an integer ‘k’. You need to perform the following operation exactly k times to maximize your score: Select an element from nums, remove it from the array, and add a new element with a value one greater than the selected element. The score is increased by the value of the selected element. Your task is to return the maximum score you can achieve after performing the operation exactly k times.
You are given two integer arrays A and B, each of length n, which are permutations of numbers from 1 to n. You need to find the prefix common array of A and B. The prefix common array is defined as an array C where each C[i] represents the number of integers that appear at or before index i in both A and B.
You are given a 2D matrix grid of size m x n, where each cell can either be a land cell (represented by 0) or a water cell (represented by a positive integer indicating the number of fish present in that cell). A fisher can start at any water cell and perform two operations any number of times: catch all the fish in the current cell or move to an adjacent water cell. Your task is to determine the maximum number of fish the fisher can catch if they start at the optimal water cell.
In a bowling game, two players take turns to hit pins. Each player hits a certain number of pins per turn, and the total score is calculated based on how many pins they hit and whether they hit 10 pins in previous turns. If a player hits 10 pins in one of the previous two turns, their score for the current turn is doubled. The objective is to determine which player has the higher score after all turns have been played.