Skip to content

Improved tasks 106, 373, 1751, 2286 #650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 25, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package g0101_0200.s0107_binary_tree_level_order_traversal_ii

import com_github_leetcode.TreeNode
import java.util.Collections
import kotlin.collections.ArrayList

/*
* Example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package g0301_0400.s0373_find_k_pairs_with_smallest_sums
// #Medium #Array #Heap_Priority_Queue #2022_11_22_Time_1809_ms_(80.95%)_Space_119.1_MB_(66.67%)

import java.util.PriorityQueue
import kotlin.collections.ArrayList

class Solution {
private class Node(index: Int, num1: Int, num2: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@ package g1701_1800.s1751_maximum_number_of_events_that_can_be_attended_ii
// #Hard #Array #Dynamic_Programming #Binary_Search
// #2023_06_18_Time_608_ms_(100.00%)_Space_104.6_MB_(100.00%)

import java.util.Arrays

@Suppress("NAME_SHADOWING")
class Solution {
fun maxValue(events: Array<IntArray>, k: Int): Int {
if (k == 1) {
val value = Arrays.stream(events).max({ a: IntArray, b: IntArray -> a[2].compareTo(b[2]) })
return if (value.isPresent) {
value.get()[2]
} else {
throw NullPointerException()
}
val value = events.maxByOrNull { it[2] }
return value?.get(2) ?: throw NullPointerException()
}
val n = events.size
events.sortWith { a: IntArray, b: IntArray -> a[0].compareTo(b[0]) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package g2201_2300.s2286_booking_concert_tickets_in_groups
// #2023_06_28_Time_1292_ms_(100.00%)_Space_98.3_MB_(100.00%)

import java.util.ArrayDeque
import java.util.Arrays
import java.util.Deque

@Suppress("NAME_SHADOWING")
Expand Down Expand Up @@ -35,8 +34,8 @@ class BookMyShow(n: Int, private val m: Int) {
numZerosLeft = IntArray(this.n + 2)
// initialize max and total, for max we firstly set values to m
// segments of size 1 are placed starting from this.n - 1
Arrays.fill(max, this.n - 1, this.n + n - 1, m)
Arrays.fill(total, this.n - 1, this.n + n - 1, m.toLong())
max.fill(m, this.n - 1, this.n + n - 1)
total.fill(m.toLong(), this.n - 1, this.n + n - 1)
// calculate values of max and total for segments based on values of their children
var i = this.n - 2
var i1 = i * 2 + 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,12 @@ internal class SolutionTest {
equalTo(9)
)
}

@Test
fun maxValue4() {
assertThat(
Solution().maxValue(arrayOf(intArrayOf(1, 2, 4), intArrayOf(3, 4, 3), intArrayOf(2, 3, 10)), 1),
equalTo(10)
)
}
}