✅ [Accepted] Solution for Swift
\nDisclaimer: By using any content from this post or thread, you release the author(s) from all liability and warranties of any kind. You can are to use the con
<blockquote>\n<b>Disclaimer:</b> By using any content from this post or thread, you release the author(s) from all liability and warranties of any kind. You can are to use the content as you see fit. Any suggestions for improvement are welcome and greatly appreciated! Happy coding!\n</blockquote>\n\n```swift\nclass Solution {\n    func avoidFlood(_ rains: [Int]) -> [Int] {\n        var res = [Int](repeating: -1, count: rains.count)\n        var wat = [Int:[Int]](), flds = [Int]()\n        for r in 0..<rains.count {\n            let nth = rains[r]\n            if nth == 0 {\n                flds.append(r)\n            } else {\n                if wat[nth] == nil {\n                    wat[nth] = [1,r]\n                } else {\n                    let dry = wat[nth]![1]\n                    guard !flds.isEmpty, flds.last! > dry else { return [] }\n                    for d in 0..<flds.count where flds[d] > dry {\n                        res[flds[d]] = nth\n                        flds.remove(at: d)\n                        wat[nth]![1] = r\n                        break\n                    }\n                }\n            }\n        }\n        flds.forEach{ res[$0] = 1 }\n        return res\n    }\n}\n```\n\n<hr>\n\n<details>\n<summary><img src="https://git.io/JDblm" height="24"> <b>TEST CASES</b></summary>\n\n<pre>\nResult: Executed 3 tests, with 0 failures (0 unexpected) in 0.024 (0.026) seconds\n</pre>\n\n```swift\nimport XCTest\n\nclass Tests: XCTestCase {\n    \n    private let solution = Solution()\n    \n    func test0() {\n        let value = solution.avoidFlood([1,2,3,4])\n        XCTAssertEqual(value, [-1,-1,-1,-1])\n    }\n    \n    func test1() {\n        let value = solution.avoidFlood([1,2,0,0,2,1])\n        XCTAssertEqual(value, [-1,-1,2,1,-1,-1])\n    }\n    \n    func test2() {\n        let value = solution.avoidFlood([1,2,0,1,2])\n        XCTAssertEqual(value, [])\n    }\n}\n\nTests.defaultTestSuite.run()\n```\n\n</details>
['Swift']