I have an array of numbers which can be a value of either 1 or 0.
I need to create a function that detects if there is one instance where there is a consecutive 1 and no other 1 exist outside of that instance, returns true else false
So to sum it up here's a clearer view of the constraints to return true:
- must have only one set of consecutive
1 - there must be no other
1outside of that one instance of consecutive1
Test cases:
[0, 0, 1, 1, 0, 0] true
[1, 0, 1, 0, 0, 0] false
[1, 0, 1, 1, 0, 0] false
[1, 1, 0, 1, 1, 0] false
[0, 1, 1, 1, 1, 0] true
[0, 0, 1, 1, 1, 1] true
1, once it does, it will flag that it started to detect the1. Once that flag is detected, it will continue to check for more1s. If there are more than one1already and it has detected a0and has detected another1, then it returnsfalse, otherwisetrue. My problem is with that in mind[0, 0, 1, 1]would be incorrect since it hasn't detected a0yet.