This is a fun problem to solve and also relatively very easy. I was able to solve this with just one try.
class Solution {
fun validWordSquare(words: List<String>): Boolean {
words.sortedBy {it.length}
for(i in 0 until words.size){
val word = words[i]
val verticalWord = words.map {if(i < it.length) it[i] else "" }.joinToString("")
if(word != verticalWord) return false
}
return true
}
}
Runtime: 244 ms, faster than 100.00% of Kotlin online submissions for Valid Word Square.
Memory Usage: 38.6 MB, less than 100.00% of Kotlin online submissions for Valid Word Square.