Problem Solving

LeetCode 226 | Invert Binary Tree | Python | Solution

Invert Binary Tree is one of the most popular programming problems. It’s an easy problem. I assume that you have a basic understanding of Binary Tree and Recursion. LeetCode 226 The problem description is straightforward. Simply put, we have to invert a binary tree and then return the root. More precisely, to solve this, we […]

LeetCode 199 | Binary Tree Right Side View | Python | Solution

If you know about the level order traversal algorithm, finding the right-side view of a binary tree becomes easy for you. This problem is nothing but a simple extended version of that. If you want to know about Level Order Traversal, I will encourage you to read this blog. LeetCode 199 The problem description is

Number of 1 Bits | LeetCode 191 | Python | Solution

To solve this ‘number of 1 bits‘ problem, we have to count the number of ‘1’ bits from an unsigned integer. It’s an easy problem if you know about bit manipulation. Let’s see how we can solve it. LeetCode 191 Mainly we will use ‘>>‘ (shift right) to solve this problem. Shift right is one

Max Area of Island | LeetCode 695 | Python | Solution

‘Max Area of Island’ is a graph problem. I assume you already have a basic understanding of Graph and DFS algorithms. This problem is almost similar to the number of islands problem. I wrote about it in my blog. LeetCode 695 Problem Overview (Max Area of Island) Before getting into the problem, read the description

Recursion | An Awesome Method for Solving Problems

Before getting into details, you don’t need to be disappointed if you don’t understand the recursion quickly. Initially, it may seem a bit complex or fuzzy to you. But don’t worry, it still seems vague to me. That’s why I will try to write on this topic to make it a little clearer to myself.

Number of Islands | LeetCode 200 | Python | Solution

LeetCode 200 The number of islands is one of the most popular programming problems. Read the problem description first. Before getting into the solution, I assume you already know about the DFS algorithm. We will use this algorithm to solve this problem. The four edges and ‘0’s will be counted as water in the given

Same Tree | LeetCode 100 | Python | Solution

LeetCode 100 It’s an easy LeetCode problem, and the description is concise and straightforward. We can solve this problem using the DFS algorithm. From two binary trees, we have to check whether both are the same or not. Consider the following cases for two different nodes. If both nodes are null, we can say that

Kth Smallest Element in a BST | LeetCode 230 | Python | Solution

LeetCode 230 I hope you already know about Binary Search Tree. In BST, each node is greater than its left subtree and smaller than its right subtree. If we print all the nodes of a BST using an inorder traversal algorithm, we will get the sorted value in ascending order. Inorder traversal follows the rule:

Binary Tree Level Order Traversal | LeetCode 102 | Python | Solution

LeetCode 102 This problem just simply the implementation of the level order traversal algorithm. If you don’t know about level order traversal yet, you can check my blog on this topic. As we know, using level order traversal, we traverse through the tree level by level. But in this problem, we have to separate values

Maximum Depth of Binary Tree | LeetCode 104 | Python | Solution

LeetCode 104 It’s a common and basic type of problem. The problem title is self-explanatory. We all know about a binary tree. To solve this problem, we have to find the maximum depth of a binary tree. We can solve this using both DFS and BFS algorithms. I am going to use the DFS solution.

Scroll to Top