Walmart Interview Question

Given a sorted array of infinite length, how would you find a certain value?

Interview Answers

Anonymous

Jan 4, 2016

Binary Search would find the number in O(logn) time complexity.

4

Anonymous

Aug 29, 2017

for binary search you will need the length of the array right? how will you find the middle element?

1

Anonymous

Jun 10, 2018

I think this is a tricky language. The array can not have an infinite list as it a limited data structure and requires us to define the size while creating. So the solution is Binary Search [O(n)] with the reasoning that an array can not be of infinite length.

Anonymous

Jun 10, 2018

I think this is a tricky language. The array having an infinite length means we do not know the size of the array. So we need to find the range first where this number will fall in. The very obvious approach is to take 1st element as low and 2nd element as high. If the number is >= high, shift low = high and high = 2 * previous position in the array and apply the binary search. The time complexity should be [O(Log(n)^2].