All Posts

Leetcode 886: Possible Bipartition

You are given a group of n people, labeled from 1 to n. Each person may dislike other people, and they should not be placed in the same group. Your task is to determine if it is possible to split the group of people into two subgroups, such that no one in the same group dislikes each other. Each pair of dislikes is represented by an array of two people who cannot be in the same group. Return true if such a split is possible, otherwise return false.

Leetcode 909: Snakes and Ladders

You are given an n x n integer matrix board where the cells are numbered from 1 to n² in a zigzag pattern starting from the bottom-left corner. Each cell may contain either -1 (indicating no special feature) or a number indicating a snake or ladder destination. You start at square 1 and can roll a 6-sided die to move between 1 and 6 steps. If you land on a square with a snake or ladder, you must move to its destination. Determine the minimum number of dice rolls needed to reach the final square . Return -1 if it is not possible.

Leetcode 919: Complete Binary Tree Inserter

You are given a complete binary tree. A complete binary tree is one where every level, except possibly the last, is completely filled, and all nodes are as far left as possible. Your task is to design a data structure that supports inserting new nodes while maintaining the completeness of the binary tree. Implement the CBTInserter class that supports two operations: inserting a new node and returning the root of the tree.

Leetcode 934: Shortest Bridge

You are given an n x n binary matrix where 1 represents land and 0 represents water. There are exactly two islands in the grid, and you need to connect them by flipping the smallest number of 0’s to 1’s. An island is a group of 1’s that are connected horizontally or vertically. Your task is to find the minimum number of flips required to connect the two islands.

Leetcode 958: Check Completeness of a Binary Tree

You are given the root of a binary tree. Determine if the tree is a complete binary tree. A complete binary tree is defined as follows: every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible.

Leetcode 959: Regions Cut By Slashes

You are given an n x n grid where each cell contains one of the following characters: ‘/’, ‘', or ’ ‘. These characters divide the grid into different regions. Your task is to determine how many distinct regions the grid is divided into.