🚴‍♂️ Find the Highest Altitude | LeetCode Solutions in Python 💻
Intuition\nMy first thought to solve this problem is to use an incremental approach. Given that we start at altitude 0, we can keep adding the \'gain\' at each 
# Intuition\nMy first thought to solve this problem is to use an incremental approach. Given that we start at altitude 0, we can keep adding the \'gain\' at each step to get the new altitude and track the maximum altitude reached at any point. This approach makes sense as the altitude at a given point is simply the sum of all the gains till that point.\n\nhttps://www.youtube.com/watch?v=xKg7CkstOaM\n\n# Approach\nWe start by initializing two variables, \'max_altitude\' and \'current_altitude\', both to 0. Then, we loop through the \'gain\' list, adding each value to \'current_altitude\'. After each addition, we compare \'current_altitude\' with \'max_altitude\'. If \'current_altitude\' is greater, we update \'max_altitude\' to the new value. The logic behind this is simple - we are climbing up (or down) a mountain, and we keep track of the highest point we\'ve reached so far. Once we\'ve gone through the entire list, we return \'max_altitude\' as the highest altitude reached.\n\n# Complexity\n- Time complexity:\nThe time complexity of this solution is O(n), where n is the length of the \'gain\' list. This is because we are traversing the \'gain\' list once.\n\n- Space complexity:\nThe space complexity of the solution is O(1). This is because we are using a constant amount of space to store the current and maximum altitudes, regardless of the input size.\n\n# Code\n```python []\nclass Solution:\n    def largestAltitude(self, gain: List[int]) -> int:\n        # Initialize the maximum altitude and the current altitude to 0 \n        max_altitude = 0 \n        current_altitude = 0    \n        # Loop through the gain list \n        for g in gain: \n            # Add the current gain to the current altitude \n            current_altitude += g \n            # Check if the current altitude is higher than the max altitude \n            if current_altitude > max_altitude: \n                # If it is, update the max altitude \n                max_altitude = current_altitude \n        # Return the max altitude \n        return max_altitude \n```\n```javascript []\nvar largestAltitude = function(gain) {\n    let maxAltitude = 0;\n    let currentAltitude = 0;\n    \n    for(let g of gain) {\n        currentAltitude += g;\n        if(currentAltitude > maxAltitude)\n            maxAltitude = currentAltitude;\n    }\n    return maxAltitude;\n};\n```\n```rust []\nimpl Solution {\n    pub fn largest_altitude(gain: Vec<i32>) -> i32 {\n        let mut max_altitude = 0;\n        let mut current_altitude = 0;\n\n        for &g in gain.iter() {\n            current_altitude += g;\n            if current_altitude > max_altitude {\n                max_altitude = current_altitude;\n            }\n        }\n        max_altitude\n    }\n}\n```\n```Go []\nfunc largestAltitude(gain []int) int {\n    maxAltitude := 0\n    currentAltitude := 0\n    \n    for _, g := range gain {\n        currentAltitude += g\n        if currentAltitude > maxAltitude {\n            maxAltitude = currentAltitude\n        }\n    }\n    return maxAltitude\n}\n\n```\n```C# []\npublic class Solution {\n    public int LargestAltitude(int[] gain) {\n        int maxAltitude = 0;\n        int currentAltitude = 0;\n        \n        foreach(int g in gain){\n            currentAltitude += g;\n            if(currentAltitude > maxAltitude)\n                maxAltitude = currentAltitude;\n        }\n        return maxAltitude;\n    }\n}\n```\n
['Go', 'Python3', 'Rust', 'JavaScript', 'C#']