Home
Gaurav's GitHub Page
Cancel

Linked List Cycle

PROBLEM DESCRIPTION: Linked List Cycle - Find Start of Cycle If there is a cycle in the LinkedList, find the Node where the cycle starts. SOLUTION We can easily find if the cycle exists by usi...

Power Function

Problem Description Given integers A and N, find A power N. (Recursive Approach) leetcode Solution A simple way to solve recursively is by doing something like: public static int calc(int a, i...

Reverse String

Problem Description Given a character array, reverse it. Reverse String Solution We can use recursion for this, although it will not be O(1) space complexity. The other approach is to use two po...

Find Leader in an Array (Carry Forward Technique)

Problem Description Given an array, find the numbers of leaders in the array. A leader is an element which is strictly greater than all the elements on its right. We can consider the last element ...

Subarray with 0 sum

Problem Description Given an array of positive and negative numbers, find if there is a subarray (of size at-least one) with 0 sum. Subarray with 0 sum Solution If the sum of elements for a gi...

Equilibrium Index of an Array

Problem Description Check if there is any index for which the sum of all elements on the left side equals sum of all elements on the right. Equilibrium Index of an Array Solution We can make use...

Prefix Sum Array

Problem Description Find prefix Array Sum of a given array. Prefix Sum Array Solution package com.arrays; import java.util.Arrays; public class PrefixSum { public static void main(String[] a...

Path Sum - Binary Tree

PROBLEM DESCRIPTION: Path Sum Binary Search Tree Given the root of a binary tree and an integer targetSum, return true if the tree has a root-to-leaf path such that adding up all the values along ...

Symmetric Binary Tree

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; * ...