All Posts

Leetcode 2602: Minimum Operations to Make All Array Elements Equal

You are given an array nums consisting of positive integers. You are also given an array queries, and for each query, you need to determine the minimum number of operations required to make all elements of nums equal to the query value. The allowed operation is to either increase or decrease an element by 1.

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 2812: Find the Safest Path in a Grid

You are given a square grid of size n x n, where each cell contains either a thief (represented by 1) or is empty (represented by 0). You start at the top-left corner of the grid and must find the maximum safeness factor for a path to the bottom-right corner. The safeness factor is defined as the minimum Manhattan distance from any cell in the path to the nearest thief.

Leetcode 2817: Minimum Absolute Difference Between Elements With Constraint

You are given a 0-indexed integer array nums and an integer x. Find the minimum absolute difference between two elements in the array such that their indices are at least x apart.

Leetcode 2824: Count Pairs Whose Sum is Less than Target

You are given a 0-indexed integer array nums and an integer target. Return the number of distinct pairs (i, j) such that 0 <= i < j < n and nums[i] + nums[j] < target.

Leetcode 2826: Sorting Three Groups

You are given an array nums containing elements that are either 1, 2, or 3. In each operation, you can remove an element from the array. The task is to return the minimum number of operations required to make the array non-decreasing.