JAVA - Simple and easy to understand || TC- O(n)  || SC - O(1)
Approach - According to the question we are required to find the maximum difference between the adjacent elements .The answer will be the maximum difference out
**Approach** - According to the question we are required to find the maximum difference between the adjacent elements .The answer will be the maximum difference out of all differences calculated .\nNow it is very obvious to think that maximum difference can only be possible if we find the maximum element lying ahead of any element ,so we start from end.\nWe take a max variable and initialize it to last element and start the loop from second last position.\n\n**Our plan is to maintain a max value which will be the greatest among all elements that are to the right side of that element so that we don\'t need to traverse every time to find the max element and hence the maximum difference,we can directly subtract the max value  from the element and get the difference.**\nAlso we store that difference in a diff variable initialized to zero. As we want to get the maximum difference we don\'t update it everytime when we find the difference , rather we do it only when we get a difference that is greater than previously calculated differences .\nIn this way we find the maximum difference using a single loop in **TC - O(N)** and **SC -O(1)**\n\n\n\n```\nCode block\n```\n\n    public int maximumDifference(int[] arr) \n\t{\n        int max=arr[arr.length-1] ,  diff=-1;\n        for(int i=arr.length-2;i>=0;i--)\n        {\n              if(max>arr[i])\n                diff=Math.max(diff,max-arr[i]);\n            else\n                max=arr[i];\n\t\t\t\t// update max if we find a element greater than it.\n        }\n        return diff;\n    }\n\n\n\n**Please upvote if u find it helpful and worth reading**
['Java']