Given an infinite size array with only 0s and 1s and sorted. find the transition point where 0s end
2015-01-18 23:27
603 查看
转自 :http://www.careercup.com/question?id=9691840
0of 0 votes27AnswersGiven an infinite size array with only 0s and 1s and sorted. find the transition point where 0s end or 1s start (written test question. coding)
- Avinash Ega on July
04, 2011 Report Duplicate | FlagAmazon Software
Engineer / Developer Arrays AlgorithmEmail me when people comment.More Questions from This Interview4of 4voteThis can be done by modified binary search.....1.At first check the 2^i the index i=0,1,2,....2.If '1' occurs at some point of index [example say 32 i.e. 2^5]3.Apply binary search between 2^4 and 2^5 [in infinite array the problem is we ill not have the info of high to apply binary search....]correct me if i am wrong ,thanks in advance..
- n20084753 on
July 21, 2011 | FlagReply0of 0 votesyours is right I think
- Anonymous on July 26,
2011 | Flag0of 0voteThe idea is to find upper bound for 1 by exponentially increasing the index in power of 2 and then finding the transition index by exponentially decreasing the index.Similar to binary search.Complexity 2*log(N+1) where N is the transition index.
Amazon Interview Question Software Engineer / Developers
0of 0 votes27AnswersGiven an infinite size array with only 0s and 1s and sorted. find the transition point where 0s end or 1s start (written test question. coding)- Avinash Ega on July
04, 2011 Report Duplicate | FlagAmazon Software
Engineer / Developer Arrays AlgorithmEmail me when people comment.More Questions from This Interview4of 4voteThis can be done by modified binary search.....1.At first check the 2^i the index i=0,1,2,....2.If '1' occurs at some point of index [example say 32 i.e. 2^5]3.Apply binary search between 2^4 and 2^5 [in infinite array the problem is we ill not have the info of high to apply binary search....]correct me if i am wrong ,thanks in advance..
- n20084753 on
July 21, 2011 | FlagReply0of 0 votesyours is right I think
- Anonymous on July 26,
2011 | Flag0of 0voteThe idea is to find upper bound for 1 by exponentially increasing the index in power of 2 and then finding the transition index by exponentially decreasing the index.Similar to binary search.Complexity 2*log(N+1) where N is the transition index.
A is the input array 1. start=0, end=1, mid=0 2. if((A[start]==0)&&(A[end]==1)) return start; 3. while(A[end] != 1) start=end; end=end<<;1; 4. while(A[start+1] != 1) mid=(start+end)/2; if(A[mid]==0) start=mid; else end=mid; 5. return start;
相关文章推荐
- Given an array of positive and negative integers find the first subarray with zero sum
- Given an array of size n, find all the possible sub set of the array of size k
- '__curl_rule_01__'declared as an array with a negative size
- Given an array [a1b2c3d4] convert to [abcd1234] with 0(1) space and O(n) time
- xcode更新到5.1,"__curl_rule_01__' declared as an array with a negative size"
- Data Structure Array: Given an array of of size n and a number k, find all elements that appear more than n/k times
- Why do some structures end with an array of size 1?
- Given an array of size N in which every number is between 1 and N, determine if there are any dupli
- Given an array of size n, find the majority element. The majority element is the element that appear
- __curl_rule_01__ declared as an array with a negative size
- Whats the best way to split an array in ruby into multiple smaller arrays of random size
- ValueError: setting an array element with a sequence.
- The installer cannot read the mwinstall.dll file, This is probably due to a CD reader which can only read files with an eight.th
- Given an array of characters which form a sentence of words, give an efficient algorithm to reverse
- ValueError: setting an array element with a sequence.
- Given an array of integers, sort the array according to frequency of elements
- Given an array of numbers, return array of products of all other numbers (no division)
- Given an array of ages (integers) sorted lowest to highest, output the number of occurrences for eac
- Err:The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array
- Given an array nums, write a function to move all 0's to the end of it while maintaining the relativ