From 9600e7af483f91fc6699044b2ccdc5c9783b9a94 Mon Sep 17 00:00:00 2001 From: kajaldotpy Date: Thu, 5 Oct 2023 09:43:17 +0530 Subject: [PATCH 1/2] issue825 --- ihQrkg/26PeRb.kt | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 ihQrkg/26PeRb.kt diff --git a/ihQrkg/26PeRb.kt b/ihQrkg/26PeRb.kt new file mode 100644 index 00000000..e4250c1c --- /dev/null +++ b/ihQrkg/26PeRb.kt @@ -0,0 +1,43 @@ +fun maxSumSubarrayWithKEvens(arr: IntArray, k: Int): Pair { + var left = 0 + var evenCount = 0 + var maxSum = 0 + var maxLeft = 0 + var maxRight = 0 + + for (right in arr.indices) { + if (arr[right] % 2 == 0) { + evenCount++ + } + + while (evenCount > k) { + if (arr[left] % 2 == 0) { + evenCount-- + } + left++ + } + + val currentSum = arr.sliceArray(left..right).sum() + + if (currentSum > maxSum) { + maxSum = currentSum + maxLeft = left + maxRight = right + } + } + + return Pair(maxLeft, maxRight) +} + +fun main() { + val arr = intArrayOf(1, 2, 3, 4, 6, 8, 10, 12, 14) + val k = 2 + + val result = maxSumSubarrayWithKEvens(arr, k) + + println("Maximum sum subarray with at most $k even integers:") + for (i in result.first..result.second) { + print("${arr[i]} ") + } + println("\nSum: ${arr.sliceArray(result.first..result.second).sum()}") +} From aca48fdcabe2c10a8b864f556a80c729120a1870 Mon Sep 17 00:00:00 2001 From: kajaldotpy Date: Thu, 5 Oct 2023 12:52:34 +0530 Subject: [PATCH 2/2] issue893 --- GAcmbw/a5HLL3.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 GAcmbw/a5HLL3.py diff --git a/GAcmbw/a5HLL3.py b/GAcmbw/a5HLL3.py new file mode 100644 index 00000000..2ead9d28 --- /dev/null +++ b/GAcmbw/a5HLL3.py @@ -0,0 +1,5 @@ +my_list = [10, 20, 30, 40, 50] # Example list + +# Access the third item (index 2) and print it +third_item = my_list[2] +print(third_item)