讨论几道M家的题# JobHunting - 待字闺中
D*e
1 楼
1. Given n arrays, find n number such that sum of their differences is
minimum. For e.g. if there are three arrays
A = {4, 10, 15, 20}
B = {1, 13, 29}
C = {5, 14, 28}
find three numbers a, b, c such that |a-b| + |b-c| + |c-a| is minimum. Here
the answer is a = 15, b = 13, and c = 14
2. Given an array of +ve and -ve integers, re-arrange it so that u have +ves
on one end and -ves on other,BUT RETAIN ORDER OF APPEARANCE..
for eg,
1,7,-5,9,-12,15
ans=
-5,-12,1,7,9,15
do it in O(n) without using any extra space.
3.Given two sorted positive integer arrays A(n) and B(n), we define a set S
= {(a,b) | a \in A and b\in B}. Obviously there are n2 elements in S. The
value of such a pair is defined as Val(a,b) = a + b. Now we want to get the
n pairs from S with largest values.
minimum. For e.g. if there are three arrays
A = {4, 10, 15, 20}
B = {1, 13, 29}
C = {5, 14, 28}
find three numbers a, b, c such that |a-b| + |b-c| + |c-a| is minimum. Here
the answer is a = 15, b = 13, and c = 14
2. Given an array of +ve and -ve integers, re-arrange it so that u have +ves
on one end and -ves on other,BUT RETAIN ORDER OF APPEARANCE..
for eg,
1,7,-5,9,-12,15
ans=
-5,-12,1,7,9,15
do it in O(n) without using any extra space.
3.Given two sorted positive integer arrays A(n) and B(n), we define a set S
= {(a,b) | a \in A and b\in B}. Obviously there are n2 elements in S. The
value of such a pair is defined as Val(a,b) = a + b. Now we want to get the
n pairs from S with largest values.