Compute sparse dot product and count islands | Meta Interview Question