Skip to content
This repository has been archived by the owner on Oct 7, 2023. It is now read-only.

issue825 #892

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions GAcmbw/a5HLL3.py
Original file line number Diff line number Diff line change
@@ -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)
43 changes: 43 additions & 0 deletions ihQrkg/26PeRb.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
fun maxSumSubarrayWithKEvens(arr: IntArray, k: Int): Pair<Int, Int> {
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()}")
}