All Posts

Leetcode 1722: Minimize Hamming Distance After Swap Operations

You are given two integer arrays, source and target, both of length n, and an array allowedSwaps containing pairs of indices where swapping is allowed. You can perform multiple swaps between the specified pairs to minimize the Hamming distance between source and target. The Hamming distance is the number of indices where the elements of source and target differ.

Leetcode 1743: Restore the Array From Adjacent Pairs

You are given an integer array nums with unique elements, but you have forgotten it. However, you do remember every pair of adjacent elements in nums. You are given a 2D integer array adjacentPairs where each adjacentPairs[i] = [ui, vi] indicates that the elements ui and vi are adjacent in nums. Your task is to reconstruct the original array nums using these adjacent pairs. There could be multiple valid solutions, so return any one of them.

Leetcode 1905: Count Sub Islands

You are given two m x n binary matrices, grid1 and grid2, where each cell can either be 0 (representing water) or 1 (representing land). An island is a group of connected 1’s, connected either horizontally or vertically. An island in grid2 is considered a sub-island if there is a corresponding island in grid1 that contains all the cells of the island in grid2. Your task is to determine the number of sub-islands in grid2.

Leetcode 1971: Find if Path Exists in Graph

You are given a graph with n vertices labeled from 0 to n-1 (inclusive) and edges connecting pairs of vertices. Your task is to determine if there exists a valid path from a given source vertex to a destination vertex. The graph is undirected, and each pair of vertices is connected by at most one edge. The vertices are connected by edges as given in the input.

Leetcode 1992: Find All Groups of Farmland

You are given an m x n binary matrix representing a piece of land, where ‘1’ denotes farmland and ‘0’ denotes forest. Your task is to identify the coordinates of each rectangular group of contiguous farmland (1’s), where each group of farmland is isolated and not adjacent to another group. Return a list of 4-length arrays, where each array represents the top-left and bottom-right coordinates of a rectangular farmland group.

Leetcode 1993: Operations on Tree

You are given a tree with n nodes numbered from 0 to n - 1 represented by a parent array. You need to implement the LockingTree class with methods for locking, unlocking, and upgrading nodes in the tree based on certain conditions.