Path with Minimum Effort - Leetcode 1631 - Python