@@ -38,5 +38,6 @@ My solutions to LeetCode problems in Kotlin.
38
38
|[2914](https://leetcode.com/problems/minimum-number-of-changes-to-make-binary-string-beautiful/)|[Minimum Number of Changes to Make Binary String Beautiful](src/main/kotlin/com/schmoczer/leetcode/_2914/MinChanges.kt)| Medium |
39
39
|[2924](https://leetcode.com/problems/find-champion-ii/)|[Find Champion II](src/main/kotlin/com/schmoczer/leetcode/_2924/FindChampionII.kt)| Medium |
40
40
|[3011](https://leetcode.com/problems/find-if-array-can-be-sorted/)|[Find if Array Can Be Sorted](src/main/kotlin/com/schmoczer/leetcode/_3011/FindIfArrayCanBeSorted.kt)| Medium |
41
+
|[3133](https://leetcode.com/problems/minimum-array-end/)|[Minimum Array End](src/main/kotlin/com/schmoczer/leetcode/_3133/MinimumArrayEnd.kt)| Medium |
41
42
|[3163](https://leetcode.com/problems/string-compression-iii/)|[String Compression III](src/main/kotlin/com/schmoczer/leetcode/_3163/StringCompression3.kt)| Medium |
42
43
|[3254](https://leetcode.com/problems/find-the-power-of-k-size-subarrays-i/)|[Find the Power of K-Size Subarrays I](src/main/kotlin/com/schmoczer/leetcode/_3254/FindThePowerOfKSizeSubarrays.kt)| Medium |
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,13 @@
1
+
packagecom.schmoczer.leetcode._3133
2
+
3
+
classMinimumArrayEnd {
4
+
funminEnd(n:Int, x:Int): Long {
5
+
var count =0
6
+
var result = x.toLong()
7
+
while (count < n -1) {
8
+
result = (result +1) or x.toLong()
9
+
count++
10
+
}
11
+
return result
12
+
}
13
+
}
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,23 @@
1
+
# Minimum Array End
2
+
3
+
You are given two integers `n` and `x`. You have to construct an array of positive integers `nums` of size `n` where for
4
+
every `0 <= i < n - 1`, `nums[i + 1]` is greater than `nums[i]`, and the result of the bitwise `AND` operation between
5
+
all elements of `nums` is `x`.
6
+
7
+
Return the minimum possible value of `nums[n - 1]`.
8
+
9
+
Example 1:
10
+
11
+
> Input: n = 3, x = 4
12
+
>
13
+
> Output: 6
14
+
15
+
Example 2:
16
+
17
+
> Input: n = 2, x = 7
18
+
>
19
+
> Output: 15
20
+
21
+
Constraints:
22
+
23
+
-`1 <= n, x <= 10^8`
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,36 @@
1
+
packagecom.schmoczer.leetcode._3133
2
+
3
+
importorg.junit.jupiter.api.BeforeEach
4
+
importkotlin.test.Test
5
+
importkotlin.test.assertEquals
6
+
7
+
classMinimumArrayEndTest {
8
+
privatelateinitvar sut:MinimumArrayEnd
9
+
10
+
@BeforeEach
11
+
funsetUp() {
12
+
sut =MinimumArrayEnd()
13
+
}
14
+
15
+
@Test
16
+
fun`when n = 3 and x = 4 then array end is 6`() {
17
+
val n =3
18
+
val x =4
19
+
val expected:Long=6
20
+
21
+
val result = sut.minEnd(n, x)
22
+
23
+
assertEquals(expected, result)
24
+
}
25
+
26
+
@Test
27
+
fun`when n = 2 and x = 7 then array end is 15`() {
0 commit comments