From fe99c0912479158c16735947628d19d0c7aba533 Mon Sep 17 00:00:00 2001 From: Darren Yao Date: Mon, 13 Jul 2020 11:02:35 -0700 Subject: [PATCH] Update Sliding.mdx --- content/4_Silver/Sliding.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/4_Silver/Sliding.mdx b/content/4_Silver/Sliding.mdx index f2895bb..e28d8e8 100644 --- a/content/4_Silver/Sliding.mdx +++ b/content/4_Silver/Sliding.mdx @@ -59,7 +59,7 @@ Two pointers refers to iterating two monotonic pointers across an array to searc Let's envision a **sliding window** (or constant size subarray) of size $K$ moving left to right along an array, $a$. -For each position of the window, we want to compute some information. For example, we could store a `std::set` of integers representing the integers inside the window. If the window currently spans the range $i \dots j$, we observe that moving the range forward to $i+1 \dots j+1$ only removes $a_i$ and adds $a_{j+1}$ to the window. We can support these two operations and query for the minimum / maximum in the set in $O(\log N)$. +For each position of the window, we want to compute some information. For example, we could store an ordered set of integers representing the integers inside the window. If the window currently spans the range $i \dots j$, we observe that moving the range forward to $i+1 \dots j+1$ only removes $a_i$ and adds $a_{j+1}$ to the window. We can support these two operations and query for the minimum / maximum in the set in $O(\log N)$. To compute the sum in the range, instead of using a set, we can store a variable $s$ representing the sum. As we move the window forward, we update $s$ by subtracting $a_i$ from $s$ and adding $a_{j+1}$ to $s$.