Wednesday, 7 August 2013

Find if an array is a sequence in O(n) time and O(1) space

Find if an array is a sequence in O(n) time and O(1) space

Given an array which might contain duplicates, How can we find if it is a
sequence?
Eg. {7, 3, 5, 4, 6, 2}
is a sequence 2, 3, 4, 5, 6, 7
Sorting is an obvious solution. How can we do this in O(n) time and O(1)
space?

No comments:

Post a Comment