• + 0 comments

    Kotlin solution with O(n)

    	var editedText = ""
    
            val breakerPoint = sqrt(s.length.toDouble()).toInt()
            val map = mutableMapOf<Int,String>()
    
            s.forEachIndexed { index, c ->
                map[index % (breakerPoint)] = (map[index % (breakerPoint)]?: "") + c
            }
            map.values.forEachIndexed { index, s ->
                editedText += s
                if (index != map.size - 1) {
                    editedText += " "
                }
            }