DSA interview question
A server monitor records a binary array, one entry per minute: 1 if the service was up and 0 if it was down. The reliability report needs the longest uninterrupted uptime streak, which is the longest run of consecutive 1s. It's a single pass with a running counter that resets at every 0, and it's the simplest example of the "track the current run, remember the best run" pattern that appears in many harder array problems.
Example: [1, 1, 0, 1, 1, 1] → 3.
int findMaxConsecutiveOnes(const vector<int>& nums); // nums contains only 0s and 1s
Input nums | Output | Explanation |
|---|---|---|
[1, 1, 0, 1, 1, 1] | 3 | The streak at the end |
[1, 0, 1, 1, 0, 1] | 2 | |
[0, 0] | 0 | No 1s at all |
[1] | 1 | |
[1, 1, 1, 1] | 4 | The whole array |
[] | 0 |
(Confirm: the array is binary; return 0 when there are no 1s.)
On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in