easy-problems

First Bad Version | Leetcode | Solution

Hi, In this post we will be discussing the first bad version problem present on LeetCode Video Solution Problem Statement You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous …

First Bad Version | Leetcode | Solution Read More »

Hamming Distance

Problem Statement The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calculate the Hamming distance. Note:0 ≤ x, y < 231. Sample Test Cases Problem Solution 1)We find XOR of x and y , Why?Because the xor makes the bit to set if the bits bits are different ie, …

Hamming Distance Read More »

Convert Sorted Array To Binary Search Tree

Problem Statement Given an array where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. Sample Test Case Problem Solution Since …

Convert Sorted Array To Binary Search Tree Read More »

Find if a tree is symmetric or not

Problem Statement Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). Sample Test Cases Problem Solution A tree is symmetric if the left subtree is a mirror reflection of the right subtree. Two trees are a mirror reflection of each other if: Their two roots have the …

Find if a tree is symmetric or not Read More »

Count Good Nodes In Binary Tree | LeetCode

Problem Source Given a binary tree containing N nodes, where each node contains some value. Count the number of good nodes in the tree. Count Good Nodes In Binary Tree Video Explanation Count Good Nodes In Binary Tree Solution For example, in the below tree The nodes marked in blue are good nodes, because they …

Count Good Nodes In Binary Tree | LeetCode Read More »

Deepest Leaves Sum | LeetCode

Problem Source Given a binary tree with N nodes. Each node in the binary tree contains some value associated with it. Find the sum of values present in the leaf nodes present at highest depth. For example for the tree given below, the sum is 7 + 8 = 15. Because and 7 and 8 …

Deepest Leaves Sum | LeetCode Read More »

How to check if two binary trees are identical ?

Given two binary trees, write a program to check if the two binary trees are identical or not ? Solution We can solve the above problem recursively. If the root node of the tree is equal then we check for the equality of left subtree and right subtree.Similarly, we check for the equality of the …

How to check if two binary trees are identical ? Read More »

Find Missing Number In An Array Without Using Extra Space

Given an array of size n-1 which contains all the numbers within range 1 to n with exactly one number as missing. Find that missing number without using any extra space. Test Cases Test Case 1 Input: 1 2 4Output: 3Explanation: 3 is missing in the above array. Test Case 2 Input: 1 3 4 …

Find Missing Number In An Array Without Using Extra Space Read More »

Sort an array in one swap where two elements are swapped by mistake

Given an array of size n in which two elements were swapped by mistake. Sort this array in one swap. It is guaranteed that such a solution exists. This array doesn’t contain duplicates Test Cases Example Input 1 Input Array: 1 2 3 6 5 4Expected Output: 1 2 3 4 5 6In the above …

Sort an array in one swap where two elements are swapped by mistake Read More »

Scroll to Top

Full Stack Integrated Bootcamp Free Trial

  • Please enter a number from 7000000000 to 9999999999.