Find the index X in a list from where the value changes
1 Answer
Find the index X in a list from where the value changes
| Flag | PURGE
You are given a list of integers. You can call only one method on the list:getItemAt(x), which will return the integer at the index x from the list.
The list starts with value 0 and it goes on to have value 0 continuously until some index. After the index the list continues to have value 1 till the end.
You do not know the size of the list. Its huge. You need to find the index from where the value 1 begins in the list.
Email me when people comment.
Email me when people comment.
Loading...
An error occurred in subscribing you.
Email me when people comment.
Email me when people comment.
Loading...
An error occurred in subscribing you.
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
How about skipping every other node until you reach value 1 and then check n-1 if the value is 1 or not. That can give you the index in O(n/2) time
- Jovaughn July 11, 2013