I came across this interesting programming challenge and couldn't help but dig in and solve it for myself. The solution below is a re-write of the approach I found in this book. My first (less efficient) solution involved a breadth first traversal of a histogram "graph" storing visited & filled cells in a HashSet.
The follow up question to this is even more interesting:
"Solve this problem with an algorithm that accesses A's elements in order and can read an element only once. Use minimal additional space."