![JAR search and dependency download from the Maven repository](/logo.png)
g2401_2500.s2456_most_popular_video_creator.Solution.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-kotlin Show documentation
Show all versions of leetcode-in-kotlin Show documentation
Kotlin-based LeetCode algorithm problem solutions, regularly updated
package g2401_2500.s2456_most_popular_video_creator
// #Medium #Array #String #Hash_Table #Sorting #Heap_Priority_Queue
// #2023_07_04_Time_1162_ms_(100.00%)_Space_101.5_MB_(100.00%)
class Solution {
fun mostPopularCreator(creators: Array, ids: Array, views: IntArray): List> {
val totalViews = HashMap()
val maxView = HashMap()
var globalMaxView: Long = 0
for (i in creators.indices) {
val currentView = totalViews.getOrDefault(creators[i], 0L) + views[i]
globalMaxView = Math.max(currentView, globalMaxView)
totalViews[creators[i]] = currentView
val lastIndex = maxView.getOrDefault(creators[i], -1)
if (!maxView.containsKey(creators[i]) || views[lastIndex] < views[i] ||
views[lastIndex] == views[i] && ids[lastIndex].compareTo(
ids[i]
) > 0
) {
maxView[creators[i]] = i
}
}
val res: MutableList> = ArrayList()
for ((key, value) in totalViews) {
if (value == globalMaxView) {
res.add(listOf(key, ids[maxView[key]!!]))
}
}
return res
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy