My Solution In JavaScript🥰
Intuition\n Describe your first thoughts on how to solve this problem. \nI solved the problem by iterating through the array of integers. For each element, I ca
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nI solved the problem by iterating through the array of integers. For each element, I calculated two values: maxSumWithDeletion, which represents the maximum sum with the possibility of deleting one element, and maxSumWithoutDeletion, which represents the maximum sum without any deletion. I updated these values based on the current element and the previous values, ensuring that at each step, I consider whether it\'s better to include the current element or start a new subarray. The final result is the maximum of these values and is returned as the answer. This approach efficiently handles the constraints and variations in the array to find the maximum sum with the given conditions.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe approach I used to solve the problem is based on dynamic programming. Dynamic programming is a technique where you break down a problem into smaller subproblems and solve each subproblem only once, storing the results in a way that avoids redundant calculations.\n\nIn this specific problem, I used two variables, maxSumWithDeletion and maxSumWithoutDeletion, to keep track of the maximum sum considering the possibility of deleting one element and without deleting any element, respectively. I iterated through the array of integers and at each step, I updated these variables based on the current element and the previous values. This way, I considered the best choice between keeping the current element in the subarray or starting a new subarray.\n\nBy updating these variables in each iteration and keeping track of the maximum sum found so far in the result variable, I ensured that I found the maximum sum for a non-empty subarray with at most one element deletion.\n\nThis approach allows for an efficient way of finding the maximum sum while considering the given conditions and constraints of the problem.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nThe time complexity of the provided code is **O(n)**, where n is the length of the input array. This is because the code iterates through the array once, performing constant-time operations at each iteration.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nThe space complexity of the code is **O(1)**, which means it uses a constant amount of extra space regardless of the size of the input array. This is because the code only uses a few variables (maxSumWithoutDeletion, maxSumWithDeletion, and result) to store intermediate results, and the space they occupy does not depend on the input size.\n\n# Code\n```\n/**\n * @param {number[]} arr\n * @return {number}\n */\nfunction maximumSum(arr) {\n  let n = arr.length;\n  let maxSumWithoutDeletion = arr[0];\n  let maxSumWithDeletion = 0;\n  let result = arr[0];\n\n  for (let i = 1; i < n; i++) {\n    maxSumWithDeletion = Math.max(maxSumWithoutDeletion, maxSumWithDeletion + arr[i]);\n    maxSumWithoutDeletion = Math.max(maxSumWithoutDeletion + arr[i], arr[i]);\n    result = Math.max(result, maxSumWithoutDeletion, maxSumWithDeletion);\n  }\n\n  return result;\n}\n```\n![Screenshot 2023-08-19 042259.png](https://assets.leetcode.com/users/images/3f92e857-7f08-4d42-96b5-1eb11a2d9b2a_1692400011.055322.png)\n
['JavaScript']