Search in Infinite Sorted 0-1 Array Problem Statement

You are provided with an infinite sorted array that consists exclusively of 0s followed by 1s. Your task is to determine the index of the first occurrence of the number 1 in this array.

Example:

Input:
Array = [0, 0, 0, 0, 1, 1, 1, 1, ...]
Output:
4
Explanation:

In the given array, the first occurrence of '1' is at index 4. Therefore, the answer is 4.

Constraints:

  • 0 <= ARR[i] <= 1
  • Time limit: 1 second

Note:

The array is infinite, hence you won't receive the actual array. Instead, you can access its elements using a function called get(i), which returns the value at index i.

Note that the provided input does not directly represent the infinite array. Instead, it indicates the index of the first occurrence of 1, which remains hidden. Your implementation should ensure that the answer fits into a 64-bit integer.

Input:

The only input line contains an integer X, the index of the first occurrence of 1. (Hidden to the user)

Output:

Print an integer denoting the index of the first occurrence of 1.
AnswerBot
4mo

Find the index of the first occurrence of 1 in an infinite sorted 0-1 array.

  • Use binary search to efficiently find the index of the first occurrence of 1.

  • Keep doubling the search range until you find a...read more

Help your peers!
Select
Add answer anonymously...

Procol Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Power of a Number Problem You are given two integers, X and N. Your task is to c...read more
A Software Developer Intern was asked Q. Minimum Operations to Equalize Array Given an integer array ARR of length N wher...read more
A Software Developer Intern was asked Q. Search in Infinite Sorted 0-1 Array Problem Statement You are provided with an i...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Power of a Number Problem You are given two integers, X and N. Your task is to c...read more
A Software Developer Intern was asked Q2. Minimum Operations to Equalize Array Given an integer array ARR of length N wher...read more
A Software Developer Intern was asked Q3. Pair Sum Problem Statement You are given an integer array 'ARR' of size 'N' and ...read more
Procol Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits