I was hoping someone can help me with the logic of a searching function.
I will have an array filled with 1s and 0s (on and off). I will get the input to find the number of consequtive off bits. I then want to return the positions in the array in which those consequtive bits are found. I will then pass that returned array onto another function, which will in turn, turn them on. I would turn them on in this function, but due to the nature of the search I cant do it all in one function.
I was going to have two pointers which point to the begining of the array. Move one pointer until it encounters a 0. When it finds a 0, move the second pointer to the location of the first. Check if the required bits are available by moving the first pointer, if so, get the locations of those, by moving the second pointer to the first, and save the array locations, which I will return.
Is there another way in which to approach this?
Also, I dont know how I would save those locations, which I want to return.