Yes, It's that easy 🤗🤗
Welcome, I hope you like this Solution \uD83E\uDD17\uD83E\uDD17\n# Approach\n1. Character Differences:\n\n    - Imagine each letter as having a number associate
# Welcome, I hope you like this Solution \uD83E\uDD17\uD83E\uDD17\n# Approach\n1. `Character Differences:`\n\n    - Imagine each letter as having a number associated with it (its position in the alphabet). \'a\' is 1, \'b\' is 2, and so on. \n    - The code looks at each pair of neighboring letters and finds the difference between their numbers. For example, the difference between \'b\' and \'a\' is 1, and the difference between \'c\' and \'b\' is also 1.\n\n2. `Absolute Differences:`\n\n    - Sometimes, differences can be negative (e.g., \'a\' - \'b\' = -1). We don\'t want negative values, so we use a special function called abs (short for absolute value) to make all the differences positive. So, even if \'a\' - \'b\' is -1, the abs function turns it into 1.\n3. `Adding Up the Differences:`\n\n    - The code keeps a running total of all these positive differences. This total is the "score" of the string. A higher score means the letters in the string are more spread out in the alphabet.\n\n# Complexity\n- **Time complexity:**\n**The time complexity of this function is $$O(n)$$, where \'n\' is the length of the input string s. Here\'s why:**\n\n    - `Loop:` The primary work is done in the for loop, which iterates through the string once.\n\n    - `Constant Operations:` Inside the loop, each iteration performs a constant amount of work.\n\n\n---\n\n\n- **Space complexity:**\n**The space complexity of this function is $$O(1)$$, which means it uses constant space. This is because:**\n\n    - Fixed Variables: The function uses a fixed number of variables (score, i).\n\n    - No Additional Data Structures: It doesn\'t create any data structures (like arrays or maps) whose size would depend on the input string.\n\n\n\n# Code\n\n```go []\nfunc scoreOfString(s string) int {\n    score := 0\n\n    for i := 1; i < len(s); i++ {\n        curr := int(s[i])\n        prev := int(s[i - 1])\n\n        score += abs(curr - prev)\n    }\n    return score\n}\n\n\nfunc abs(x int) int {\n    if x < 0 {\n        return -x\n    }\n    return x\n}\n```\n```python []\ndef score_of_string(s):\n    score = 0\n    if len(s) <= 1:\n        return score\n\n    for i in range(1, len(s)):\n        score += abs(ord(s[i]) - ord(s[i - 1]))  # Use ord() for ASCII values\n    return score\n```\n```Java []\nclass Solution {\n    public static int scoreOfString(String s) {\n        int score = 0;\n        if (s == null || s.length() <= 1) {\n            return score;\n        }\n\n        for (int i = 1; i < s.length(); i++) {\n            score += Math.abs(s.charAt(i) - s.charAt(i - 1));\n        }\n        return score;\n    }\n}\n```\n
['String', 'Java', 'Go', 'Python3']