You are given the root of a binary tree, and two integers val and depth. You need to add a row of nodes with value val at the given depth depth. The root node is considered to be at depth 1.
Given the root of a binary tree, construct a matrix representation of the tree using specific formatting rules to place each node in the appropriate position in the matrix.
You are given the root of a binary tree. Determine the maximum width of the tree, which is defined as the maximum width among all levels. The width of a level is the distance between the leftmost and rightmost non-null nodes, including null nodes in between that would be present in a complete binary tree.
You are in a room with n bulbs, all initially turned on. There are four buttons on the wall, each with a different functionality: flip all bulbs, flip even-numbered bulbs, flip odd-numbered bulbs, and flip bulbs with labels j = 3k + 1. You need to make exactly presses presses. For each press, you can choose any button. Return the number of distinct possible configurations of the bulbs after performing all the presses.
You are given a graph that started as a tree with n nodes. One additional edge has been added, creating a cycle. Your task is to find and return the redundant edge that, when removed, would turn the graph back into a tree.
You are given a binary matrix of size m x n, where 1 represents land and 0 represents water. An island is a group of 1’s connected horizontally or vertically. Return the area of the largest island. If there are no islands, return 0.