Home
Gaurav's GitHub Page
Cancel

Palindrome LinkedList

PROBLEM DESCRIPTION Given the head of a singly linked list, return true if it is a palindrome. Palindrome LinkedList SOLUTION Using Stack (O(n) space complexity) class Solution { public ...

Reverse a LinkedList

PROBLEM DESCRIPTION Reverse a given LinkedList. Reverse a LinkedList SOLUTION ITERATIVE APPROACH class Solution { public ListNode reverseList(ListNode head) { if(head ==...

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