You are not logged in. Please login at www.codechef.com to post your questions!

×

# What is the best solution to this problem

 0 . You are given a file which contains a very bit sequence of 0 and 1 and it is sorted. Hence all the zeros are in front of the ones.One needs to find the first orrcurance of of 1 in the file(return the position). The only method to access the file is through a method whose signature is — int getBitAtPosition(int position) — which returns the bit at the specified position in the file. I thought of using a binary search till the 1 is not found ....once it was found we can keep on decreasing the position linearly and saving the previous value so that if the bit at pos-- is 0 then we can get the position as pos asked 18 Jan '15, 12:36 191●6●20 accept rate: 14%

 0 If you do a linear traversal after binary search you can still end up having the time complexity to be be of linear order. But if you do a lower bound binary search you can achieve a time complexity of log(n). Check the below solution it will have a time complexity of log(n) even in the worst case Lower_bound answered 28 Nov '17, 23:59 3★athulpai 17●5 accept rate: 0%
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×633
×210
×19
×2

question asked: 18 Jan '15, 12:36

question was seen: 1,704 times

last updated: 28 Nov '17, 23:59