Kotlin Easy Union Find
Find the number of the islands, and connect them with islands - 1\n\n\nclass Solution {\n  private lateinit var parents: IntArray\n\n  private fun find(x: Int):
Find the number of the islands, and connect them with `islands - 1`\n\n```\nclass Solution {\n  private lateinit var parents: IntArray\n\n  private fun find(x: Int): Int {\n    if (parents[x] != x) parents[x] = find(parents[x])\n    return parents[x]\n  }\n  private fun union(x: Int, y: Int) {\n    val px = find(x)\n    val py = find(y)\n    parents[py] = px\n  }\n  fun makeConnected(n: Int, connections: Array<IntArray>): Int {\n    if (connections.size < (n - 1)) return -1\n    parents = IntArray(n + 1) { it }\n    for ((a, b) in connections) union(a, b)\n    var res = 0\n    for(i in 0 until n)\n      if (find(i) == i) res++\n    return res - 1\n  }\n}\n\n```
['Kotlin']