Understand how to apply the sliding-window technique to solve relevant array problems
The sliding-window technique allow us to iteratively analyse subarrays ("windows") of varying sizes in an array by storing and independently incrementing a start and end index of the current subarray. Read this Stack Overflow answer for an intuitive explanation.
After attempting each problem, find solutions in the Leaderboard tab (HackerRank, may be on left side of page) or Solution or Discuss tabs (LeetCode) on that problem's page. If you get stuck for more than 15 minutes, review and understand the solutions and move on. Come back and re-attempt the problem after a few days.
Sum of All Odd-Length Subarrays (LeetCode)
Note: There is no need to attempt the O(n)
solution for now. The O(n)
solution requires math that may not be the most relevant to us while we are practising JavaScript.
Hint: Would nested loops be helpful, an outer loop that determines the length of the subarray, and an inner loop that sums all subarrays of a given length?
Rocket solution code (Python)
Maximum Number of Vowels in a Substring of Given Length (LeetCode)
Longest Turbulent Subarray (LeetCode)
Longest Continuous Subarray with Absolute Difference Less Than or Equal to Limit (LeetCode)
Grumpy Bookstore Owner (LeetCode)
Hint: We may want to create a helper function that calculates the number of customers satisfied in a given day, given the specific days that the bookstore owner is not grumpy.
Max Consecutive Ones III (LeetCode)
Hint: What determines the start and end of the sliding window?
Hint: Do we need to track the indexes of 0s in the array?
Rocket solution code (Python)
Rocket solution video (Python)
Longest Repeating Character Replacement (LeetCode)