✅☑️ Beats 100% || Easiest Possible Solution || Beginner friendly
image.png\n\n# Intuition\nIterating through the list:\n\nFor each element i in the input list nums, the code checks whether i is less than or equal to the curre
image.png\n![image.png](https://assets.leetcode.com/users/images/2a4eb526-9837-4315-8eb9-935119db8c00_1712041220.9211383.png)\n# Intuition\n**Iterating through the list:**\n\nFor each element i in the input list nums, the code checks whether i is less than or equal to the current minimum value minn.\n\nIf i is less than or equal to minn, it updates minn to i, effectively updating the minimum value seen so far.\n\nIf i is greater than minn, it calculates the difference between i and minn and checks if it is greater than the current maximum difference diff. If it is, diff is updated to this new maximum difference.\n\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# PYTHON 3\n```\nclass Solution:\n    def maximumDifference(self, nums: List[int]) -> int:\n        minn = 1e9\n        diff = -1\n        for i in nums:\n            if i <= minn:\n                minn = i\n            else:\n                diff = max(diff,i-minn)\n        return diff\n```\n\n# JAVA\n```\nclass Solution {\n    public int maximumDifference(int[] nums) {\n        int minn = Integer.MAX_VALUE;\n        int diff = -1;\n        for (int i : nums) {\n            if (i <= minn) {\n                minn = i;\n            } else {\n                diff = Math.max(diff, i - minn);\n            }\n        }\n        return diff;\n    }\n}\n```\n\n# CPP\n```\nclass Solution {\npublic:\n    int maximumDifference(vector<int>& nums) {\n        int minn = 1e9;\n        int diff = -1;\n        for (int i : nums) {\n            if (i <= minn) {\n                minn = i;\n            } else {\n                diff = max(diff, i - minn);\n            }\n        }\n        return diff;\n    }\n};\n
['Array', 'Math', 'Two Pointers', 'Python', 'C++', 'Java', 'Python3']