Home
Gaurav's GitHub Page
Cancel

Squares of a Sorted Array

Problem Description Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order. Squares of a Sorted Array Solution T...

Remove nth Node From End of LinkedList

PROBLEM DESCRIPTION: Remove nth Node From End of LinkedList Given a LinkedList and an integer n, remove nth Node from the end of the list. SOLUTION One approach that will work is to first get th...

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