Interview Questions

Algorithm to find the two numbers whose difference is minimum among the set of numbers.

Software QA/Tests Interview Questions from Microsoft


(Continued from previous question...)

Algorithm to find the two numbers whose difference is minimum among the set of numbers.

Q:
Microsoft Interview Question for SDE in tests about Algorithm
Difference is Minimum
Algorithm to find the two numbers whose difference is minimum among the set of numbers.

For example the sequence is 5, 13, 7, 0, 10, 20, 1, 15, 4, 19

The algorithm should return min diff = 20-19 = 1.

Constraint - Time Complexity O(N) and Space is not a constraint [upto O(3N)]

Assumption - Sorting O(nlogn) and comparison of adjacent numbers is already known and is not an option. Try to keep it linear

(Continued on next question...)

Other Interview Questions