JAVA || EASYY || WITH EXPLANATION || BEATS 99.87% 🔥
Intuition\nWe can iterate over each character using for loop. Calculate absolute differnce between each adjacent character and add it to sum.\n\n# Approach\n1) 
# Intuition\nWe can iterate over each character using for loop. Calculate absolute differnce between each adjacent character and add it to sum.\n\n# Approach\n1) Create Variables `sum` to store the total sum , `first`to store the value of first element and `scnd` to store the value of second element.\n2) For loop starting from `index 0` to `s.length()-1`\n    - `int first = (int)(s.charAt(i))` store ASCII value of 1st char\n    - `int scnd = (int)(s.charAt(i+1))` store ASCII  value of 2nd char\n    - `sum += Math.abs(first-scnd)` to calculate the absolute difference between first and second character and add it to sum \n3) Return `sum`\n\n\n# Complexity\n- Time complexity:**O(n)**  where n is the length of the input string s.\n- Space complexity:**O(1)**   as only a constant amount of extra space is used\n\n# Code\n```\nclass Solution {\n    public int scoreOfString(String s) {\n        int sum = 0;\n        for(int i = 0;i<s.length()-1;i++) {\n            int first = (int)(s.charAt(i));\n            int scnd = (int)(s.charAt(i+1));\n            sum += Math.abs(first-scnd);\n        }\n        return sum;\n    }\n}\n```
['Java']