Leaderboard
Showing:
Handle Score
@Ibrahim Nash 6420
@blackshadows 6376
@mb1973 5604
@Quandray 5231
@akhayrutdinov 5111
@saiujwal13083 4510
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3413
Complete Leaderboard
Last index of One
Basic Accuracy: 67.38% Submissions: 3974 Points: 1

Given a string S consisting only '0's and '1's,  find the last index of the '1' present in it.

 

Example 1:

Input:
S = 00001
Output:
4
Explanation:
Last index of  1 in given string is 4.

 

Example 2:

Input:
0
Output:
-1
Explanation:
Since, 1 is not present, so output is -1.

 


Your Task:  
You don't need to read input or print anything. Your task is to complete the function lastIndex() which takes the string S as inputs and returns
the last index of '1'. If '1' is not present, return "-1" (without quotes).

 

Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)

 

Constraints:
1 <= |S| <= 106
S = {0,1}

 

 


 

 

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Last index of One

Output Window