Find Position of First One
Given a sorted array of integers of size N, consisting only of 0's and 1's, identify the position of the first occurrence of '1', using 1-based indexing.
If the array contains only 0's with no '1's, return -1.
Input:
The first line contains an integer 't', denoting the number of test cases.
Each test case consists of:
- An integer N, the size of the array.
- N space-separated integers of only ‘0’s and ‘1’s in sorted order.
Output:
For each test case, output the position of the first ‘1’. If no ‘1’ is present, print “-1”. Each test case should be output on a new line.
Example:
Input:
t = 2
N = 5
Array = [0, 0, 0, 1, 1]
N = 3
Array = [0, 0, 0]
Output:
4
-1
Constraints:
1 ≤ t ≤ 100
0 ≤ N ≤ 104
Note: Implement the function without printing anything directly, as the output handling is managed elsewhere.

AnswerBot
4mo
Find the position of the first occurrence of '1' in a sorted array of 0's and 1's.
Iterate through the array and find the index of the first '1'.
Return the index + 1 as the position (1-based indexing)....read more
Help your peers!
Add answer anonymously...
TCS System Engineer interview questions & answers
A System Engineer was asked 6d agoQ. What are the best practices for making API calls in Python?
A System Engineer was asked 1w agoQ. How proficient are you in Python?
A System Engineer was asked 1w agoQ. What is unsupervised and supervised machine learning?
Popular interview questions of System Engineer
A System Engineer was asked 6d agoQ1. What are the best practices for making API calls in Python?
A System Engineer was asked 1w agoQ2. How proficient are you in Python?
A System Engineer was asked 1w agoQ3. What is unsupervised and supervised machine learning?
Top HR questions asked in TCS System Engineer
A System Engineer was asked 1mo agoQ1. Are you open to the possibility of relocating?
A System Engineer was asked 1mo agoQ2. What can you explain about internships and the differences between mini and majo...read more
A System Engineer was asked 1mo agoQ3. Can you describe the project you completed at the university level?
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

