Swift | One-Liner
One-Liner, terse (accepted answer)\n\nclass Solution {\n  func maximizeWin(_ p: [Int], _ k: Int) -> Int {\n     p.indices.reduce(into:(0,0,[0])){while p[$0.0]<p
**One-Liner, terse (accepted answer)**\n```\nclass Solution {\n  func maximizeWin(_ p: [Int], _ k: Int) -> Int {\n     p.indices.reduce(into:(0,0,[0])){while p[$0.0]<p[$1]-k{$0.0+=1};let x=$1-$0.0+1;$0.1=max($0.1,x+$0.2[$0.0]);$0.2+=[max($0.2[$1],x)]}.1\n  }\n}\n```\n\n---\n\n**One-Liner, expanded and annotated (accepted answer)**\n```\nclass Solution {\n    func maximizeWin(_ prizePositions: [Int], _ k: Int) -> Int {\n        prizePositions.indices.reduce(into: (\n            result: 0,\n            trailingSegLower: 0, // lower bounds of second segment\n            dp: [0]  // each element is max prize count (delta X) for the prize at this location\n        )) { data, leadingSegLower in\n            while prizePositions[data.trailingSegLower] < prizePositions[leadingSegLower] - k {\n                data.trailingSegLower += 1\n            }\n            let leadingSegPrizeCount = leadingSegLower - data.trailingSegLower + 1\n            let trailingSegPrizeCount = data.dp[data.trailingSegLower]\n            data.result = max(data.result, leadingSegPrizeCount + trailingSegPrizeCount)\n            data.dp.append(max(data.dp[leadingSegLower], leadingSegPrizeCount))\n        }.result\n    }\n}\n```
['Swift']