# 239. Sliding Window maximum Leetcode Solution

## Sliding Window maximum Leetcode Problem :

You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position.

Return the max sliding window.

## Sliding Window maximum Leetcode Solution :

### Constraints :

• 1 <= nums.length <= 105
• -104 <= nums[i] <= 104
• 1 <= k <= nums.length

### Example 1:

• Input: nums = [1], k = 1
• Output: [1]

Intuition :

For query range problem we mainly use segment tree which reduces the time complexity.

Approach :

First we build segment tree, then we store the maximum element for each range, then for each query if we go out of bound then we return INT_MIN or if it whole lies in our range we simply return the maximum element in that range

### Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

## Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others