Write a function: `int numIslands(boolean[] grid, int w, int h)`

that returns the number of islands in `grid`

. `grid`

is 1-dimensional, but represents a 2-dimensional `boolean[h][w]`

array. Example: if `h = 12`

and `w = 5`

, then `grid[7]`

represents `[1][2]`

.

Now, there is an additional constraint: can you solve this problem without modifying `grid`

, and without using `O(w*h)`

extra space?

I was asked this in a interview, and haven't figured out the solution for the constraint.