Simple approach in JS - beat 100%
Approach\n Describe your approach to solving the problem. \n- Sorting array in non-ascending order.\n- Iterating through the Sorted Array\n- Calculating the Max
# Approach\n<!-- Describe your approach to solving the problem. -->\n- Sorting array in non-ascending order.\n- Iterating through the Sorted Array\n- Calculating the Maximum Happiness Sum, The contribution is calculated by subtracting the index of the child from its happiness value.\n- Handling Non-positive Happiness Values by Math.max\n- Returning the Maximum Happiness Sum\n\n# Complexity\n- Time complexity: O(n log 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# Code\n```\n/**\n * @param {number[]} happiness\n * @param {number} k\n * @return {number}\n */\nvar maximumHappinessSum = function (happiness = [], k = 0) {\n  happiness.sort((a, b) => b - a);\n  let max = 0;\n\n  for (let i = 0; i < k; i++) {\n    max += happiness[i] - i <= 0 ? 0 : happiness[i] - i;\n  }\n\n  return max;\n};\n```
['JavaScript']