From 700a8d01071def9f06d4460f3a9df18090bb2d6a Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Tue, 19 Nov 2024 22:51:14 +0100 Subject: [PATCH] =?UTF-8?q?kt:=20add=20=C2=AB1652.=20Defuse=20the=20Bomb?= =?UTF-8?q?=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit URL: https://leetcode.com/problems/defuse-the-bomb/ Signed-off-by: Matej Focko --- kt/defuse-the-bomb.kt | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 kt/defuse-the-bomb.kt diff --git a/kt/defuse-the-bomb.kt b/kt/defuse-the-bomb.kt new file mode 100644 index 0000000..ed67c62 --- /dev/null +++ b/kt/defuse-the-bomb.kt @@ -0,0 +1,36 @@ +class Solution { + fun decrypt( + code: IntArray, + k: Int, + ): IntArray { + val decrypted = IntArray(code.size) + if (k == 0) { + return decrypted + } + + var i = 1 + if (k < 0) { + i = code.size + k + } + val kAbs = listOf(k, -k).max() + + var runningSum = 0 + for (j in i..