You are given a game board represented as an 8x8 grid, where each cell can either be free (’.’), white (‘W’), or black (‘B’). The objective is to determine if placing your piece (either ‘W’ or ‘B’) at a specified location will create a valid ‘good line’ where the line consists of three or more cells. A good line is defined as a line (horizontal, vertical, or diagonal) with endpoints of the same color and any cells between them of the opposite color.
You are tasked with designing a dynamic array where the number of elements that should be in the array at each time is provided in an integer array nums. Additionally, you are given an integer k, representing the maximum number of times you can resize the array. At each time step, the array’s size must be large enough to hold the elements in nums[i] and any extra space will be wasted. Your goal is to minimize the total wasted space by resizing the array at most k times.
You are given an array of integers piles, where each element represents the number of stones in a pile, and an integer k. You need to perform the following operation exactly k times: Choose any pile, and remove floor(piles[i] / 2) stones from it. You can apply the operation to the same pile multiple times. The goal is to minimize the total number of stones left in all piles after performing the operation k times.
You are given a string s of even length n. The string contains exactly n/2 opening brackets [ and n/2 closing brackets ]. A string is called balanced if for every opening bracket there exists a corresponding closing bracket, with each closing bracket having a matching opening bracket before it. Your task is to return the minimum number of swaps needed to make the string balanced.
You are given an array nums containing distinct integers. You need to rearrange the elements of the array such that no element is equal to the average of its two adjacent elements. Specifically, for every index i (1 <= i < nums.length - 1), the condition (nums[i-1] + nums[i+1]) / 2 != nums[i] should hold. Your task is to return any valid rearrangement of nums that satisfies this condition.
You are given a positive integer p. Consider an array nums (1-indexed) that consists of the integers in the inclusive range [1, 2p - 1] represented in binary form. You are allowed to perform the following operation any number of times: Choose two elements x and y from nums. Choose a bit in x and swap it with its corresponding bit in y. The goal is to find the minimum non-zero product of the elements in nums after performing the above operation any number of times. Return this minimum product modulo (10^9 + 7).