-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIteration1.kt
More file actions
41 lines (33 loc) · 877 Bytes
/
Iteration1.kt
File metadata and controls
41 lines (33 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
fun List<Char>.isSorted(other: List<Char>): Boolean {
for (i in this.indices) {
if (this[i] > other[i]) return false
}
return true
}
fun gridChallenge(grid: Array<String>): String {
var temp = grid.first().toList().sorted()
for (str in grid) {
val t = str.toList().sorted()
if (temp.isSorted(t))
temp = t
else return "NO"
}
return "YES"
}
fun main() {
val t = readLine()!!.trim().toInt()
for (tItr in 1..t) {
val n = readLine()!!.trim().toInt()
val grid = Array(n) { "" }
for (i in 0 until n) {
val gridItem = readLine()!!
grid[i] = gridItem
}
val result = gridChallenge(grid)
println(result)
}
}
/**
* Pretty simple one.
* Just iterate through the array, sort the strings and compare them to one anohter.
* */