All Posts

Leetcode 2616: Minimize the Maximum Difference of Pairs

You are given a 0-indexed integer array nums and an integer p. Your task is to find p pairs of indices such that the maximum absolute difference between any of the pairs is minimized. Each index can be used in at most one pair. Return the minimized value of the maximum difference among all the pairs.

Leetcode 2640: Find the Score of All Prefixes of an Array

You are given a 0-indexed integer array nums of length n. For each prefix nums[0..i], you are asked to calculate its ‘score.’ The score is defined as the sum of the conversion array of the prefix. The conversion array of a prefix is formed by the following rule: conver[i] = nums[i] + max(nums[0..i]), where max(nums[0..i]) is the maximum value in the prefix from the start to the current index.

Leetcode 2641: Cousins in Binary Tree II

Given the root of a binary tree, replace the value of each node in the tree with the sum of all its cousins’ values. Two nodes are cousins if they have the same depth but different parents. The depth of a node is the number of edges from the root to the node.

Leetcode 2645: Minimum Additions to Make Valid String

Given a string ‘word’ consisting of letters ‘a’, ‘b’, and ‘c’, you can insert letters ‘a’, ‘b’, or ‘c’ anywhere and as many times as needed. Your task is to determine the minimum number of insertions required to transform ‘word’ into a valid string. A string is considered valid if it can be formed by repeatedly concatenating the string ‘abc’.

Leetcode 2653: Sliding Subarray Beauty

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.

Leetcode 2654: Minimum Number of Operations to Make All Array Elements Equal to 1

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.