Union and Intersection of two Linked Lists

Given two linked lists, create another two linked lists to get union and intersection of the elements of existing lists. Example Input: List1: 5 → 9 → 10 → 12 → 14 List2: 3 → 5 → 9 → 14 → 21 Output: Intersection_list: 14 → 9 → 5 Union_list:   …

Read moreUnion and Intersection of two Linked Lists

Range sum queries without updates

Problem Statement The problem “Range sum queries without updates” states that you have an array of integers and a range. The problem statement asks to find out the sum of all the elements within the given range. Example arr[]={10, 9, 8, 7, 6} Query: {(0, 4), (1, 3)} 40 24 …

Read moreRange sum queries without updates

Count the number of nodes at given level in a tree using BFS

Description The problem “Count the number of nodes at given level in a tree using BFS” states that you are given a Tree (acyclic graph) and a root node, find out number of nodes at L-th level. Acyclic Graph: It is a network of nodes connected through edges which has …

Read moreCount the number of nodes at given level in a tree using BFS

Move all negative elements to end in order with extra space allowed

Problem Statement “Move all negative elements to end in order with extra space allowed” states that you are given an array containing positive and negative numbers both. The problem statement asks to move all the negative elements in the last of the array. Example arr[] = { 1,2,-3,-5,2,7,-9,-11 } 1, …

Read moreMove all negative elements to end in order with extra space allowed

Count pairs from two sorted arrays whose sum is equal to a given value x

Problem Statement “Count pairs from two sorted arrays whose sum is equal to a given value x” problem states that you are given two sorted arrays of integers and an integer value called sum. The problem statement asks to find out the total number of pair which sums up to …

Read moreCount pairs from two sorted arrays whose sum is equal to a given value x

Find the smallest positive integer value that cannot be represented as sum of any subset of a given array

Problem Statement You are given a sorted array of integers. We need to find the smallest positive integer value that cannot be represented as sum of any subset of a given array. Example arr[] = {1,4,7,8,10} 2 Explanation: Because there is not any sub-array that can represent 2 as a …

Read moreFind the smallest positive integer value that cannot be represented as sum of any subset of a given array

Count Subsets Having Distinct Even Numbers

We have all struggled with the subset problem at some point or the other in an interview. The interviewers love these problems too. These problems help them examine the understanding as well as the thought process of any student. So, without any further ado let us jump straight into the …

Read moreCount Subsets Having Distinct Even Numbers

Find Three Element From Different Three Arrays Such That a + b + c = sum

Three Sum is a problem loved by interviewers. It is a problem I was personally asked during the Amazon interview. So, without wasting any more time let us get to the problem. An array that has both positive and negative numbers. Three numbers that sum up to zero/can be modified, …

Read moreFind Three Element From Different Three Arrays Such That a + b + c = sum

Smallest Subarray With all Occurrences of a Most Frequent Element

In the smallest subarray with all occurrences of a most frequent element problem, we have given an array. Take a number “m” in an array with the maximum frequency. The problem statement says that you have to find out the smallest subarray which also has all the occurrence of number …

Read moreSmallest Subarray With all Occurrences of a Most Frequent Element