Given a 2D grid of size m x n, you are tasked with finding a new matrix where each cell value is the absolute difference between the count of distinct values in the diagonal cells to the left and above it, and the count of distinct values in the diagonal cells to the right and below it.
You are given a binary string s of length n. You can perform two types of operations: (1) Flip all characters from index 0 to i (inclusive), with a cost of i + 1. (2) Flip all characters from index i to n - 1 (inclusive), with a cost of n - i. The goal is to return the minimum cost required to make all the characters in the string equal (either all 0s or all 1s).
You are given a number n and a list of queries. Initially, an n x n matrix is filled with zeros. Each query updates either a row or a column in the matrix to a given value. After applying all the queries, compute and return the sum of all elements in the matrix.
You are given a string s consisting of digits from ‘0’ to ‘9’. A string is called semi-repetitive if there is at most one pair of adjacent identical digits. Your task is to return the length of the longest semi-repetitive substring of s.
A number of robots are standing on an infinite number line with their initial positions given in the array nums. Each robot will move based on a command string s where ‘L’ means left and ‘R’ means right. If two robots collide, they instantly reverse their directions. Your task is to calculate the sum of the distances between all pairs of robots d seconds after the command.
You are given a string s consisting of lowercase English letters. You can perform the operation of replacing every letter of a selected non-empty substring with the preceding letter in the alphabet. Your task is to return the lexicographically smallest string possible after performing the operation.