Friday, September 11, 2009

Arrays!!!

1...Having an int array, which size is infinite (no way to find out), how do you do a binary search?

2...Given an int array and an int value. Find all pairs in array that add up to value.

3...Given an array of size n, you have n-1 integers in the array, and one of the n elements is a duplicate, find an efficient method of finding the duplicate.

4...Given a sorted array and a value, determine the first pair of numbers from that array which sums up to the given value.

5...Given two Arrays, there is intersection of elements in these two arrays. So now find all the elements which are common in both these arrays.
Suppose there is an element '#' repeated 2 times in both the arrays, then in the output we need to show two '#'s

6...How to efficiently find most frequent element in an array.?

7...Given an array of integers,Print the integers whose appearance are in odd times.
Need not worry abt order while printing the output.
Need Algorithm in o(n) time complexity.
Need efficient space complexity.

8...Given an integer array {1, -20, 29, 9, 1, 100, ..., 29), please return the index of the first non-repetitive element in the array.

9...Given a set S of n distinct numbers and a positive integer k <= n. Determine the k numbers in S that are closest to the median of S. Find an O(n) algorithm

10...Given 2 sorted arrays of n elements A,B. Find the k-th smallest element in the union of A and B in O(log k) time. You can assume that there are no duplicate elements

11...How do you perform binary search on a rotated sorted array?
eg., 75, 77, 85, 91, 10, 19, 26, 29, 33,45, 67

12...Given an array of integers where some numbers repeat 1 time, some numbers repeat 2 times and only one number repeats 3 times, how do you find the number that repeat 3 times.

13...Given an array of positive numbers and negative numbers devise an algo to find max non-consecutive sum in that array.complexity should be in o(n).

14...Find the k max elements in an array of n

15...Find the sum of the most common element in a array .

16...Find a median of two sorted integer arrays.

17...Write a function that takes in an array of integers and outputs the number of ways you can combine those integers to obtain a sum of 15.
Example: for [10,5,3,2], output = 2.

18...Given an array of integers, write a function that returns the difference between the largest even integer and the smallest odd integer.
Sample input: [17 6 13 31 2 8 23]
Correct sample output: –5 (= 8 – 13)

19...I have an array that contains integers 1...n.
I remove 2 elements from that array, shuffle it and give it to a function you will write.
Find the 2 elements i removed.

No comments: