Find subarray with given sum (Handles Negative Numbers)

The problem “Find subarray with given sum (Handles Negative Numbers)” states that you are given an integer array, containing negative integers as well and a number called “sum”. The problem statement asks to print the sub-array, which sums up to a given number called “sum”.  If more than one sub-array …

Read more

Sum of minimum and maximum elements of all subarrays of size k

Problem Statement   The problem “Sum of minimum and maximum elements of all subarrays of size k” states that you are given an array containing positive and negative integers, find the sum of minimum and maximum elements of all the sub-arrays of size k. Examples   arr[] = {5, 9, 8, 3, …

Read more

Maximum Depth Of Binary Tree

Problem Statement   “Maximum depth of binary tree” problem states that you are given a binary tree data structure. Print the maximum depth of the given binary tree. Example   Input 2 Explanation: Maximum depth for the given tree is 2. Because there is only a single element below the root (i.e. …

Read more

Next Greater Element in an Array

Problem Statement   Given an array, we will find the next greater element of each element in the array. If there is no next greater element for that element then we will print -1, else we will print that element. Note: Next greater element is the element that is greater and …

Read more