PROBLEM DESCRIPTION: Symmetric Binary Tree Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center). SOLUTION class Solution { public ...
Maximum Depth of Binary Tree
Problem Description: Maximum Depth of Binary Tree Solution The bottom-up approach will look like this: /** * Definition for a binary tree node. * public class TreeNode { * int val; * ...
Binary Tree Level Order Traversal
Problem Description: Binary Tree Level Order Traversal Solution For this, we can use a Queue Data Structure. We first keep the root element already pushed in the queue. Then we dequeue “all elem...
Rotate an Array k times
Problem Description Given an Array, rotate it k times Example Array: 1 2 3 4 5 6 7 8 9 k: 3 Output: 7 8 9 1 2 3 4 5 6 leetcode Solution Array: 1 2 3 4 5 6 7 8 9 k: 3 In the output array, we ...
Reverse an Array
Problem Description: Given an Array, reverse it Solution If we swap first element with last element, then 2nd element with 2nd last element, 3rd element and 3rd last element and so on, we will f...
Reverse an Array in the given Range
Problem Description: Given an Array, reverse it Solution This is similar to how we would reverse an array, but we will need to change the start and end index. Then keep swapping the elements fro...
Binary Search Tree - Insert
PROBLEM DESCRIPTION: https://practice.geeksforgeeks.org/problems/insert-a-node-in-a-bst/1# Given a BST and a key K. If K is not present in the BST, Insert a new Node with a value equal to K into t...
String Palindrome
Problem Description: Palindrome String package com.gauk; public class Solution { /* * Given a string, determine if it is a palindrome, considering only * alphanumeric characters and igno...
Find Square Root
Problem Description Given a number N, find the square root of that number. If the number is not a perfect square, then return -1 Solution First approach - Brute Force Brute Force: Loop through ...