## Count pair with Given Sum

In problem “count pair with given sum” we have given an integer array[] and another number say ‘sum’, you have to determine whether any of the two elements in a given array has a sum equal to “sum”. Example   Input: arr []={1,3,4,6,7} and sum = 9. Output: “ Elements found …

## Move all Negative Numbers to Beginning and Positive to End with Constant Extra Space

Suppose you have an array of integers. It consists of both negative and positive numbers and the problem statement asks to shift/move all the negative and positive elements to the left of the array and to the right of the array respectively without using extra space. This will be a …

## Sum of f(a[i], a[j]) over all pairs in an array of n integers

The problem statement asks to find out the Sum of f(a[i], a[j]) over all pairs in an array of n integers in such a way that 1 < = i < j < = n considering that we are provided an array of integers. Example   arr[] = {1, 2, 3, …

## Maximum difference between first and last indexes of an element in array

Suppose, you have an array of integers. The problem “Maximum difference between first and last indexes of an element in array” asks to find out the difference between the first and last index of each number present in an array such that the difference is being maximum of all. Example   …

## Boundary Traversal of binary tree

Problem Statement   The problem “Boundary Traversal of binary tree” states that you are given a binary tree. Now you need to print the boundary view of a binary tree. Here boundary traversal means that all the nodes are shown as the boundary of the tree. The nodes are seen from …

## Find all triplets with zero sum

The problem “Find all triplets with zero sum” states that you are given an array containing positive and negative number both. The problem statement asks to find out the triplet with the sum equal to 0. Example   arr[] = {0,-2,1,3,2,-1} (-2 -1  3) (-2 0  2) (-1 0  1) Explanation …

## How to check if two given sets are disjoint?

The problem “How to check if two given sets are disjoint?” states that suppose you are given two sets in the form of array say set1[] and set2[]. Your task is to find out whether the two sets are Disjoint Sets or not. Example   inputSet1[] = {1, 15, 8, 9, …

## First element occurring k times in an array

We have given a number ‘k’ and an integer array. The problem “First element occurring k times in an array” says to find out the first element in the array which occurs exactly k times in an array. If there is no element in the array which occurs k times …

## Count Primes in Ranges

Problem Statement   The problem “Count Primes in Ranges” states that you are given a range [left, right], where 0<=left<=right<=10000. The problem statement asks to find out the total number of prime numbers within the range. Assuming that there will be a large number of queries. Example   left: 4 right:10 2 …

## Print Fibonacci sequence using 2 variables

Problem Statement   The problem “Print Fibonacci sequence using 2 variables” states that you need to print the Fibonacci sequence but there is a limitation of using only 2 variables. Example   n = 5 0 1 1 2 3 5 Explanation The output sequence has the first five elements of the … 