6 kyu
Zeros and Ones
449 of 811kodejuice
Description:
Given an array containing only zeros and ones, find the index of the zero that, if converted to one, will make the longest sequence of ones.
For instance, given the array:
[1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1]
replacing the zero at index 10 (counting from 0) forms a sequence of 9 ones:
[1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1]
'------------^------------'
Your task is to complete the function that determines where to replace a zero with a one to make the maximum length subsequence.
Notes:
- If there are multiple results, return the last one:
[1, 1, 0, 1, 1, 0, 1, 1] ==> 5
- The array will always contain only zeros and ones.
Can you do this in one pass?
Puzzles
Logic
Algorithms
Similar Kata:
Stats:
Created | Nov 6, 2017 |
Published | Nov 26, 2017 |
Warriors Trained | 2416 |
Total Skips | 90 |
Total Code Submissions | 7973 |
Total Times Completed | 811 |
JavaScript Completions | 449 |
Python Completions | 346 |
Ruby Completions | 38 |
Total Stars | 81 |
% of votes with a positive feedback rating | 93% of 182 |
Total "Very Satisfied" Votes | 159 |
Total "Somewhat Satisfied" Votes | 20 |
Total "Not Satisfied" Votes | 3 |
Total Rank Assessments | 4 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |