+ 1
Find the longest consecutive 1s in the given string (110010101110101) using c++ or java
for example I)1010110= 2 2) 10101= 1 please someone answer this question for me.
1 Odpowiedź
+ 7
Problem Breakdown / how to solve:
* Use a loop, going through each character in the string
* Use 2 variables.
- One to store the largest consecutive streak (of 1's)
- One to store the Current consecutive streak (of 1's)
* Inside the loop, if the character is a 1,the current streak is incremented
If the character is a 0, and the current streak is larger than the max streak, the max streak is set to the current streak.
Reset the current streak.
* After the loop is complete, the variable for the max streak is the answer