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 more

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 more

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 more

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 more

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 more

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 more