All Posts

Leetcode 2657: Find the Prefix Common Array of Two Arrays

You are given two integer arrays A and B, each of length n, which are permutations of numbers from 1 to n. You need to find the prefix common array of A and B. The prefix common array is defined as an array C where each C[i] represents the number of integers that appear at or before index i in both A and B.

Leetcode 2658: Maximum Number of Fish in a Grid

You are given a 2D matrix grid of size m x n, where each cell can either be a land cell (represented by 0) or a water cell (represented by a positive integer indicating the number of fish present in that cell). A fisher can start at any water cell and perform two operations any number of times: catch all the fish in the current cell or move to an adjacent water cell. Your task is to determine the maximum number of fish the fisher can catch if they start at the optimal water cell.

Leetcode 2661: First Completely Painted Row or Column

You are given a list of integers arr and a 2D matrix mat. The list arr contains all the integers from the range [1, m * n] and represents the order in which you paint the cells of mat. Each integer in arr corresponds to a cell in mat that is being painted. The goal is to find the smallest index i at which either a row or a column becomes completely painted.

Leetcode 2672: Number of Adjacent Elements With the Same Color

You are given an integer n, representing an array of n elements where all elements are initially set to 0 (uncolored). You are also given a 2D integer array queries, where each query specifies an index and a color. For each query, set the element at the specified index to the given color and then count the number of adjacent pairs of elements in the array that have the same color. Return an array answer where each element corresponds to the number of adjacent pairs with the same color after applying the corresponding query.

Leetcode 2673: Make Costs of Paths Equal in a Binary Tree

You are given a perfect binary tree with n nodes, where each node has a cost associated with it. The tree is numbered from 1 to n, with node 1 as the root. For each node i, its left child is 2*i and its right child is 2*i + 1. You are allowed to increment the cost of any node by 1 any number of times. Your task is to return the minimum number of increments required to make the total cost of the path from the root to each leaf node equal.

Leetcode 2679: Sum in a Matrix

You are given a 2D array nums where each row represents a set of numbers. You perform operations on the matrix by removing the largest number from each row at each step. After removing the largest number from each row, you identify the highest number amongst all those removed and add it to your score. Repeat this until the matrix becomes empty and return the final score.