Let's solve this using brain kernighan's algorithm. This is optimized to O(1) time and space.
Already have an account? Log in