Swift: Maximum Subarray Sum with One Deletion + Test Cases
Solution\n\nswift\nclass Solution {\n    func maximumSum(_ arr: [Int]) -> Int {\n        guard arr.count > 1 else { return arr[0] }\n        var ans = arr[0], o
##### Solution\n\n```swift\nclass Solution {\n    func maximumSum(_ arr: [Int]) -> Int {\n        guard arr.count > 1 else { return arr[0] }\n        var ans = arr[0], oneDel = 0, noDel = arr[0]\n        for i in 1..<arr.count {\n            oneDel = max(oneDel + arr[i], noDel)\n            noDel = max(noDel + arr[i], arr[i])\n            ans = max(oneDel, noDel,ans)\n        }\n        return ans\n    }\n}\n```\n\n##### Test cases\n\n```swift\nimport XCTest\n\n//      Executed 3 tests, with 0 failures (0 unexpected) in 0.005 (0.007) seconds\n\nclass Tests: XCTestCase {\n    private let s = Solution()\n    func test1() {\n        XCTAssertEqual(s.maximumSum([1,-2,0,3]), 4)\n    }\n    func test2() {\n        XCTAssertEqual(s.maximumSum([1,-2,-2,3]), 3)\n    }\n    func test3() {\n        XCTAssertEqual(s.maximumSum([-1,-1,-1,-1]), -1)\n    }\n}\n\nTests.defaultTestSuite.run()\n```
['Dynamic Programming', 'Swift']