You are on page 1of 3

# 1

Given two random integer arrays, print their intersection. That is print all the
elements that are present in both the given arrays.
Input format :
Line 1 : Array 1 Size
Line 2 : Array 1 elements (separated by space)
Line 3 : Array 2 Size
Line 4 : Array 2 elements (separated by space)
Output format : Print intersection elements in different lines
2. Pair sum in array
Given a random integer array and a number x. Find and print the pairs of element
s in the array which sum to x.
While printing a pair, print the smaller element first.
That is, if a valid pair is (6, 5) print "5 6". There is no constraint that out
of 5 pairs which have to be printed on 1st line. You can print pairs in any orde
r, just be careful about the order of elements in a pair.
Input format :
Line 1 : Array size
Line 2 : Array elements
Line 3 : x
Output format :
Line 1 : Pair 1 elements (separated by space)
Line 2 : Pair 3 elements (separated by space)
Line 3 : and so on

## 3. Pair sum in array

Given a random integer array and a number x. Find and print the pairs of element
s in the array which sum to x.
While printing a pair, print the smaller element first.
That is, if a valid pair is (6, 5) print "5 6". There is no constraint that out
of 5 pairs which have to be printed on 1st line. You can print pairs in any orde
r, just be careful about the order of elements in a pair.
Input format :
Line 1 : Array size
Line 2 : Array elements

Line 3 : x
Output format :
Line 1 : Pair 1 elements (separated by space)
Line 2 : Pair 3 elements (separated by space)
Line 3 : and so on
4. Find the Unique Element
Given an integer array of size 2N + 1. In this given array, N numbers are presen
t twice and one number is present only once in the array.
You need to find that number which is unique in the array.
Note : Given array will always contain odd number of elements.
Input format :
Line 1 : Array size i.e. 2N+1
Line 2 : Array elements (separated by space)
Sample Input :
7
2 3 1 6 3 6 2
Sample Output
1
5.Sort 0 1
You are given an integer array that contains only 0s and 1s. Write a function to
sort this array. Find a solution which scans the array only once. Don't use ext
ra array.
You need to change in the given array itself. So no need to return or print anyt
hing.
Input format :
Line 1 : Array Size
Line 2 : Array elements (separated by space)
Sample Input:
7
0 1 1 0 1 0 1
Sample Output:
0 0 0 1 1 1 1
6. Sort 0 1 2
You are given an integer array containing only 0s, 1s and 2s. Write a solution t
o sort this array only in a single scan.
You need to change in the given array itself. So no need to return or print anyt
hing.
Input format :

## Line 1 : Array Size

Line 2 : Array elements (separated by space)
Sample Input:
7
0 1 2 0 2 0 1
Sample Output:
0 0 0 1 1 2 2