You are given a 2D integer matrix grid of size n * n. The matrix contains integers in the range [1, n²], and each number appears exactly once, except for two numbers. One number a is repeated twice, and another number b is missing. Find the repeating and missing numbers a and b.
You are given an array nums of size n where n is a multiple of 3, and a positive integer k. Your task is to divide the array into n / 3 subarrays, each containing exactly 3 elements, such that the difference between the largest and smallest element in each subarray is less than or equal to k. If it’s possible to divide the array in this way, return a 2D array containing the subarrays. If it is not possible, return an empty array. If multiple valid divisions exist, return any valid one.
You are given an array nums consisting of positive integers. A polygon can be formed from the integers if it satisfies the following condition: the sum of the lengths of any k-1 sides must be greater than the length of the remaining side. The perimeter of a polygon is the sum of the lengths of its sides. Your task is to find the largest possible perimeter of a polygon that can be formed using the sides from nums, or return -1 if it is not possible to form such a polygon.
You are given an array nums containing positive integers. Your task is to find the total frequency of the elements in nums that appear the maximum number of times. The frequency of an element is defined as the number of times that element occurs in the array. You need to return the sum of frequencies of all elements that have the maximum frequency.
You are given an array nums of length n and a positive integer k. A subarray is called good if the absolute difference between its first and last element is exactly k. The task is to return the maximum sum of any good subarray of nums. If no such subarray exists, return 0.
You are given a 0-indexed string array words. You need to determine the number of index pairs (i, j) such that i < j and the string at index i is both a prefix and a suffix of the string at index j. The function isPrefixAndSuffix(str1, str2) returns true if str1 is both a prefix and a suffix of str2, and false otherwise.