Method that takes a Boolean array and returns true if the longest run of true values is greater than consecutive false values. | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 2

Method that takes a Boolean array and returns true if the longest run of true values is greater than consecutive false values.

A run of true values is a set of adjacent elements all which contain the value true. If run of True values is not greater than run of false values return false. You can assume that a longest run of either true or false exists in the array.

28th Nov 2017, 8:41 PM
Danat Gorth
Danat Gorth - avatar
6 ответов
29th Nov 2017, 3:50 AM
Adam Schmitt
Adam Schmitt - avatar
+ 1
https://code.sololearn.com/ctcs8SX3eT68/?ref=app
29th Nov 2017, 11:57 PM
Adam Schmitt
Adam Schmitt - avatar
+ 1
@Adam Schmitt I think it works for the most part, but not always for example if you try passing this array to the method: true, false, false, false, false, true, false, true, true, true, true, true it would return false, when it should return true. Since longest false run is 4 and longest true run is 5
30th Nov 2017, 8:30 PM
Danat Gorth
Danat Gorth - avatar
+ 1
@danat gorth Thanks for the tip. I had the increment to the array index set based on the absolute position of the run instead of the length of the run. The bug is now fixed and your example was added to illustrate the change.
30th Nov 2017, 9:37 PM
Adam Schmitt
Adam Schmitt - avatar
+ 1
@Adam Schmitt thanks it works.
4th Dec 2017, 7:38 PM
Danat Gorth
Danat Gorth - avatar
0
This is my attempt at it, haven't fully tested it but have tried a few scenarios. https://code.sololearn.com/cZz2V9yIL1d7/?ref=app
30th Nov 2017, 11:25 PM
Dan Walker
Dan Walker - avatar