Implement flat_map, redistribute wealth evenly | Qube Research & Technologies Interview Question