Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
isaiahliu committed Dec 10, 2024
1 parent 42ad4d4 commit ea7c010
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/main/kotlin/p27xx/Problem2717.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package p27xx

import util.expect

fun main() {
class Solution {
fun semiOrderedPermutation(nums: IntArray): Int {
var oneIndex = 0
var nIndex = 0

nums.forEachIndexed { index, num ->
when (num) {
1 -> oneIndex = index
nums.size -> nIndex = index
}
}

return oneIndex + nums.lastIndex - nIndex - if (oneIndex > nIndex) 1 else 0
}
}

expect {
Solution().semiOrderedPermutation(
intArrayOf()
)
}
}

0 comments on commit ea7c010

Please sign in to comment.