Q1. Given an array of n elements that contains elements from 0 to n-1, with any of these numbers appearing any number of times. Find these repeating numbers in O(n) and use only constant memory space.
Note: The repeating element should be printed only once.
Input: n=7, array[]={1, 2, 3, 6, 3, 6, 1
Output: 1, 3, 6
Explanation. The numbers 1.3 and 6 appear more than once in the array.
Q2. Given an array of integers, return all the elements having positive and negative values of a number that exists in the array,
Note: If no such pair exists, simply retum an empty array, also multiple pairs of the same number could exist and you need to put each of them in the array. Return the pairs in sorted order.
Expected Time Complexity O(nlog(n))
Expected Auxiliary Space, O(n)
Input: arr[] = [1, -3, 2, 3, 6,-1,-3,31
Output: 1-1. 1, -3, 3-3.3]
Explanation: The array contains both 1 and -1, and 3 &-3 two times
Top comments (0)