Skip to content

Improved tasks 3408, 3419, 3433, 3434, 3435, 3472 #770

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 1 commit into from
Mar 7, 2025
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 @@ -6,17 +6,14 @@ package g3401_3500.s3408_design_task_manager
import java.util.TreeSet

class TaskManager(tasks: List<List<Int>>) {
private val tasks: TreeSet<IntArray?>
private val taskMap: MutableMap<Int?, IntArray>
private val tasks: TreeSet<IntArray> = TreeSet<IntArray>(
Comparator { a: IntArray, b: IntArray ->
if (b[2] == a[2]) b[1] - a[1] else b[2] - a[2]
},
)
private val taskMap: MutableMap<Int, IntArray> = HashMap<Int, IntArray>()

init {
this.tasks =
TreeSet<IntArray?>(
Comparator { a: IntArray?, b: IntArray? ->
if (b!![2] == a!![2]) b[1] - a[1] else b[2] - a[2]
},
)
this.taskMap = HashMap<Int?, IntArray>()
for (task in tasks) {
val t = intArrayOf(task[0], task[1], task[2])
this.tasks.add(t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,24 @@ import kotlin.math.max
@Suppress("unused")
class Solution {
fun minMaxWeight(n: Int, edges: Array<IntArray>, threshold: Int): Int {
val reversedG: Array<MutableList<IntArray>?> = arrayOfNulls<MutableList<IntArray>?>(n)
for (i in 0..<n) {
reversedG[i] = ArrayList<IntArray>()
}
val reversedG: Array<MutableList<IntArray>> = Array<MutableList<IntArray>>(n) { ArrayList<IntArray>() }
for (i in edges) {
val a = i[0]
val b = i[1]
val w = i[2]
reversedG[b]!!.add(intArrayOf(a, w))
reversedG[b].add(intArrayOf(a, w))
}
val distance = IntArray(n)
distance.fill(Int.Companion.MAX_VALUE)
distance[0] = 0
if (reversedG[0]!!.isEmpty()) {
if (reversedG[0].isEmpty()) {
return -1
}
val que: Queue<Int?> = LinkedList<Int?>()
val que: Queue<Int> = LinkedList<Int>()
que.add(0)
while (que.isNotEmpty()) {
val cur: Int = que.poll()!!
for (next in reversedG[cur]!!) {
for (next in reversedG[cur]) {
val node = next[0]
val w = next[1]
val nextdis = max(w, distance[cur])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package g3401_3500.s3433_count_mentions_per_user
class Solution {
fun countMentions(numberOfUsers: Int, events: List<List<String>>): IntArray {
val ans = IntArray(numberOfUsers)
val l: MutableList<Int?> = ArrayList<Int?>()
val l: MutableList<Int> = ArrayList<Int>()
var c = 0
for (i in events.indices) {
val s = events[i][0]
Expand All @@ -31,7 +31,7 @@ class Solution {
val id = events[i][2].toInt()
val a = events[i][1].toInt() + 60
for (j in l.indices) {
if (l[j]!! >= a - 60 && l[j]!! < a) {
if (l[j] >= a - 60 && l[j] < a) {
ans[id]--
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import kotlin.math.max

class Solution {
fun maxFrequency(nums: IntArray, k: Int): Int {
val count: MutableMap<Int?, Int?> = HashMap<Int?, Int?>()
val count: MutableMap<Int, Int> = HashMap<Int, Int>()
for (a in nums) {
count.put(a, count.getOrDefault(a, 0)!! + 1)
count.put(a, count.getOrDefault(a, 0) + 1)
}
var res = 0
for (b in count.keys) {
res = max(res, kadane(nums, k, b!!))
res = max(res, kadane(nums, k, b))
}
return count.getOrDefault(k, 0)!! + res
return count.getOrDefault(k, 0) + res
}

private fun kadane(nums: IntArray, k: Int, b: Int): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Solution {
private val charToIdx = IntArray(26)
private val used = BooleanArray(26)

fun supersequences(words: Array<String>): MutableList<MutableList<Int?>?> {
fun supersequences(words: Array<String>): List<List<Int>> {
charToIdx.fill(-1)
for (w in words) {
used[w[0].code - 'a'.code] = true
Expand All @@ -37,7 +37,7 @@ class Solution {
}
// Try all supersets of forcedMask; keep those that kill all cycles
var best = 9999
val goodSets: MutableList<Int?> = ArrayList<Int?>()
val goodSets: MutableList<Int> = ArrayList<Int>()
for (s in 0..<(1 shl m)) {
if ((s and forcedMask) != forcedMask) {
continue
Expand All @@ -52,16 +52,16 @@ class Solution {
}
}
// Build distinct freq arrays from these sets
val seen: MutableSet<String?> = HashSet<String?>()
val ans: MutableList<MutableList<Int?>?> = ArrayList<MutableList<Int?>?>()
val seen: MutableSet<String> = HashSet<String>()
val ans: MutableList<MutableList<Int>> = ArrayList<MutableList<Int>>()
for (s in goodSets) {
val freq = IntArray(26)
for (i in 0..<m) {
freq[idxToChar[i].code - 'a'.code] = if ((s!! and (1 shl i)) != 0) 2 else 1
freq[idxToChar[i].code - 'a'.code] = if ((s and (1 shl i)) != 0) 2 else 1
}
val key = freq.contentToString()
if (seen.add(key)) {
val tmp: MutableList<Int?> = ArrayList<Int?>()
val tmp: MutableList<Int> = ArrayList<Int>()
for (f in freq) {
tmp.add(f)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Solution {
val arr = Array<IntArray>(26) { IntArray(26) }
for (i in 0..25) {
for (j in 0..25) {
arr[i][j] = min(abs(i - j), (26 - abs(i - j)))
arr[i][j] = min(abs(i - j), 26 - abs(i - j))
}
}
val dp = Array<Array<IntArray>>(n) { Array<IntArray>(n) { IntArray(k + 1) } }
Expand Down