Grokking Microsoft Coding Interview
Ask Author
Back to course home

0% completed

Solution: Sliding Window Maximum
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

You are given an array of integers nums, and integer k, size of the sliding window which moves from the very left to the very right in the array. In each window, you can have only k numbers, and the window moves one position right by each time.

Return the array containing the maximum element of each sliding window.

Examples

Example 1:

  • Input: nums = [2, 1, 5, 1, 3, 2], k = 3
  • Expected Output: [5, 5, 5, 3]
  • Justification: Here, the window of size 3 moves across the array

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible