Problem title
Difficulty
Avg time to solve

Print All The Nodes At Distance From The Target Node
Moderate
15 mins
Box Stacking
Hard
25 mins
Implement strStr()
Moderate
25 mins
Create A Matrix With Alternating X And 0
Easy
15 mins
Row Of A Matrix With Maximum Ones
Moderate
20 mins
Digit Inversion
Easy
10 mins
Min Jumps
Easy
15 mins
Game of Stones
Easy
15 mins
Santa Claus and His Magic Bag
Easy
10 mins
Compare Versions
Moderate
--
1

Position Of First One

Difficulty: EASY
Contributed By
Anish De |Level 1
Avg. time to solve
15 min
Success Rate
85%

Problem Statement

Given a sorted array of size N, consisting of only 0’s and 1’s. The problem is to find the position of first ‘1’ in the sorted array Assuming 1 based indexing.

It could be possible that the array consists of only 0’s or only 1’s. If 1’s are not present in the array then print “-1”.

Input Format:
 The first line contains an Integer 't' which denotes the number of test cases/queries to be run. 
Then the test cases follow. 

The first line of input for each test case/query contains an integer N representing the size of the array.

The second line of input for each test case/query contains N space-separated integers consisting of only ‘0’s and ‘1’s in the sorted order.
Output Format:
For each test case, print the position of the first ‘1’ in the sorted array. If 1’s are not present in the array then print “-1”.

Output for every test case will be printed in a separate line.
Note:
You do not need to print anything, it has already been taken care of. Just implement the function.
Constraints:
1 <= t <= 100
0 <= N <= 10^4

Time Limit: 1sec
Sample Input 1:
3
5
0 0 0 1 1
4
1 1 1 1
3
0 0 0
Sample Output 1:
4
1
-1
Explanation For Sample Input 1:
Test Case 1:
Three 0’s are present at the beginning and first ‘1’ is present at the 4th position.

Test Case 2:
First ‘1’ is present at the 1st position.

Test Case 3:
1’s are not present in the array so we print -1.
Reset Code
Full screen
copy-code
Console