Work Sheet 1a-DS
Work Sheet 1a-DS
1. Given an array with elements from 1 to n with a duplicated element, find the element that is duplicated.
2. Given an array with elements repeated itself many times, find the repeated element and the number of times it gets
repeated.
3. Given a binary array and an integer arrange all one’s and zero’s together arr[] = {1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1}; arr[]={0,
0, 0, 0, 1, 1, 1, 1, 1, 1, 1}.
4. Given two unsorted arrays that represent two sets (elements in every array are distinct), find union of these two arrays.
5. Given two unsorted arrays find the intersection of the two arrays.
6. Given an array of numbers, arrange them in a way that yields the largest value. For example, if the given numbers.
are {54, 546, 548, 60}, the arrangement 6054854654 gives the largest value.
//Hint: Given two numbers X and Y, compare two numbers XY (Y appended at the end of X) and YX (X appended at the
end of Y). If XY is larger, then X should come before Y in output, else Y should come before. For example, let X and
Y be 542 and 60. To compare X and Y, we compare 54260 and 60542. Since 60542 is greater than 54260, we put Y
first.
7. Given an array of integers, find the first combination of four elements in the array whose sum is equal to a given
value X.
For example, if the given array is {10, 2, 3, 4, 5, 9, 7, 8} and X = 23, then your function should print “3 5 7 8″ (3 + 5 + 7
+ 8 = 23).
8. Arrange a set of elements in an array which has positive and negative elements, such that the elements are
arranged alternatively.
9. Given two arrays that are sorted, arrange the elements of the array into a single sorted array.
10. Given three input arrays find the common elements in all the array
11. Given an array with n elements, find an element k and print the first least and the first largest element when
compared to k in the array.
12. Given an array with a range r1 to r2, assume an element is missed and an element is duplicated. Find the missing element.
13. Given an array of integers, find the closest (not considering distance, but value) greater or same value on left
of every element. If an element has no greater or same value on left side, print -1.
14. An array contains numbers ranging from 0 to n-2. There is exactly one number is repeated in the array. Find
the repeated element.
15. Find the largest and smallest element in an array.
16. Given a sorted positive integer array find the first element that cannot be represented as the sum of any two
element present in the array. Input: {1, 3, 6, 10, 11, 15}; Output: 2