Skip to content

Commit 08a9025

Browse files
author
Akash Rajpurohit
committed
✨ Day 28; Week 4 ✔️
1 parent 0f039be commit 08a9025

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
4. [Smallest Integer Divisible by K](https://leetcode.com/explore/challenge/card/november-leetcoding-challenge/567/week-4-november-22nd-november-28th/3543/) ➡️ [CPP Solution](Week4/smallestRepunitDivByK.cpp)
3939
5. [Longest Substring with At Least K Repeating Characters](https://leetcode.com/explore/challenge/card/november-leetcoding-challenge/567/week-4-november-22nd-november-28th/3544/) ➡️ [CPP Solution](Week4/longestSubstring.cpp)
4040
6. [Partition Equal Subset Sum](https://leetcode.com/explore/challenge/card/november-leetcoding-challenge/567/week-4-november-22nd-november-28th/3544/) ➡️ [CPP Solution](Week4/canPartition.cpp)
41+
7. [Sliding Window Maximum](https://leetcode.com/explore/challenge/card/november-leetcoding-challenge/567/week-4-november-22nd-november-28th/3544/) ➡️ [CPP Solution](Week4/maxSlidingWindow.cpp)
4142

4243
## Week 5 🚧
4344
Coming soon...

Week4/maxSlidingWindow.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
vector<int> maxSlidingWindow(vector<int>& nums, int k) {
4+
vector<int> res;
5+
multiset<int> s;
6+
7+
for(int i = 0; i < k; ++i) {
8+
s.insert(nums[i]);
9+
}
10+
11+
res.push_back(*(s.rbegin()));
12+
13+
for(int i = k; i < nums.size(); ++i) {
14+
s.erase(s.find(nums[i - k]));
15+
s.insert(nums[i]);
16+
res.push_back(*(s.rbegin()));
17+
}
18+
19+
return res;
20+
}
21+
};

0 commit comments

Comments
 (0)