Swift - Easy to understand solution
Intuition\nFor all the numbers in nums array find the total OR (|) of all the numbers before and after it, then apply operations to every number and calculate m
# Intuition\nFor all the numbers in nums array find the total OR (|) of all the numbers before and after it, then apply operations to every number and calculate max OR\'s\n\n# Approach\n* Create a pre array which contains the total OR\'s before the current num at i\n```swift \nlet nums = [8,2,1]\nlet pre = [0, 8, 10]\n\n// pre[2] = 10, which means total OR\'s of nums before i = 2 (8 | 2)\n// Note: pre[0] = 0 because there\'s no number before index 0\n```\n\n* Create a post array which contains the total OR\'s after the current num at i\n```swift\nlet nums = [8,2,1]\nlet post = [3, 1, 0]\n\n// post[0] = 3, which means total OR\'s of nums after i = 0 (2 | 1)\n// Note: post[2] = 0 because there\'s no number after index 2\n```\n\n* Iterate over nums and for every number apply the operation (multiplying it by 2) k times and calculate the total OR by OR\'ing pre, current and post and find the largest possible OR\n```swift\nlet i = 1\nlet currentOR = pre[i] | (nums[i] << k) | post[i]\n```\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```swift\nclass Solution {\n    func maximumOr(_ nums: [Int], _ k: Int) -> Int {\n        var n = nums.count\n        var largest = 0\n        var pre = [Int](repeating: 0, count: n)\n        var post = [Int](repeating: 0, count: n)\n\n        for i in 1 ..< n {\n            pre[i] = pre[i - 1] | nums[i - 1]\n        }\n\n        for i in stride(from: n - 2, through: 0, by: -1) {\n            post[i] = post[i + 1] | nums[i + 1]\n        }\n\n        for i in 0 ..< n {\n            let currentOR = pre[i] | nums[i] << k | post[i]\n            largest = max(largest, currentOR)\n        }\n\n        return largest\n    }\n}\n```
['Swift']