Problem Description Given an array of integers, return the start and end element (not index) which represents the maximum continuous range of numbers present in the array. Example: 1 11 3 0 15 5 2...
Sort based on Three Numbers
Problem Description You are given an array of 3 integers and another array which contains only the numbers present in the first array. The 3 numbers in the “order” array need not be sorted. You ne...
Find the Smallest Sub-Array to Sort
Problem Description You are given an array which could be unsorted. Return the start and end index of the smallest sub-array which if-sorted will make the complete array sorted. Solution Think a...
Trapping Rain Water
This question is part of NeetCode150 series. Problem Description Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap a...
Sum of all Sub-Arrays
Problem Description Return the total sum of all sub-arrays of the given array. Solution BRUTE-FORCE The brute force method is to check all sub-array, calculate its sum and add that to the total...
Sum of Linked Lists
PROBLEM DESCRIPTION Given two numbers as LinkedList in reverseOrder (most significant digit as the right most digit), return a LinkedList (reversed) as the sum. Example: LinkedListOne: 2 -&...
Kadane's Algorithm
Problem Description Given an array of numbers, find the maximum sum possible for any subarray. Solution We can use Kadane’s Algorithm to solve this. <—–positive numbers—–>&...
Sort Stack (In Place)
PROBLEM DESCRIPTION Given a stack, sort the elements in-place. (smallest element at the bottom of the stack) SOLUTION Think about: If we are given an already sorted stack and we need to add an e...
Max Path Sum in Binary Tree
PROBLEM DESCRIPTION Given a binary tree, return its max path sum. SOLUTION The apprach to this problem is similar to Binary Tree Diameter. We keep a track of two things, the sum in LST and the s...
Height Balanced Binary Tree
PROBLEM DESCRIPTION A binary tree is balanced if for each node in the tree, the difference between the height of its LST and RST is at most 1. SOLUTION public int heightBalancedBinaryTreeX(Bin...