Google Onsite Interview Question - Find consecutive triplets of true

Please correct the question if you see before -
Given an unsorted array [True, True, False, True, ...], find the count of all consecutive 3 Trues, (or flip the false to have consecutive 3 Trues, don't remember exactly...)

I solved with a naive solution doing a for loop, O(n).
Interviewer ask me to do better, I'm guessing O(logn), but I couldn't figure it out.
Would segment trees help? Or is it related to this problem Max Inserts to Obtain String Without 3 Consecutive 'a'?

Comments (3)