All Posts

Leetcode 226: Invert Binary Tree

Given the root of a binary tree, invert the tree by swapping the left and right subtrees of every node, and return its root.

Leetcode 230: Kth Smallest Element in a BST

Given the root of a binary search tree and an integer k, your task is to return the kth smallest value in the tree (1-indexed).

Leetcode 235: Lowest Common Ancestor of a Binary Search Tree

Given a Binary Search Tree (BST), find the lowest common ancestor (LCA) of two given nodes. The lowest common ancestor is the deepest node that is an ancestor of both nodes. An ancestor of a node is a node itself or any node in its path up to the root.

Leetcode 236: Lowest Common Ancestor of a Binary Tree

Given a binary tree, find the lowest common ancestor (LCA) of two given nodes. The lowest common ancestor is defined as the lowest node that is an ancestor of both nodes p and q. A node can be a descendant of itself.

Leetcode 341: Flatten Nested List Iterator

You are given a nested list of integers nestedList, where each element can either be an integer or a sublist containing integers or other sublists. Implement an iterator to flatten this nested list.

Leetcode 427: Construct Quad Tree

You are given an n x n binary grid of 0’s and 1’s. Your task is to represent this grid with a Quad-Tree. A Quad-Tree is a tree structure where each node has four children. Each internal node has two properties: val (True for a grid of 1’s or False for a grid of 0’s) and isLeaf (True if the node is a leaf, False if it has children). If the entire grid has the same value, the node is a leaf. If not, the grid is divided into four sub-grids, and the process is repeated recursively for each sub-grid. Your goal is to return the root of the Quad-Tree that represents the grid.