
g0201_0300.s0239_sliding_window_maximum.solution.go Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-all Show documentation
Show all versions of leetcode-in-all Show documentation
104 LeetCode algorithm problem solutions
package s0239_sliding_window_maximum
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Heap_Priority_Queue
// #Sliding_Window #Queue #Monotonic_Queue #Udemy_Arrays #Big_O_Time_O(n*k)_Space_O(n+k)
// #2024_03_18_Time_168_ms_(99.41%)_Space_9.3_MB_(64.37%)
func maxSlidingWindow(nums []int, k int) []int {
if k == 1 {
return nums
}
i := 1
prev := nums
var reuse []int
for ; (1 << i) <= k; i++ {
next := maxReduce(prev, 1<<(i-1), reuse)
reuse = prev
prev = next
}
if 1<
© 2015 - 2025 Weber Informatics LLC | Privacy Policy