Brute Force Approach class Solution { public int[] maxSlidingWindow(int[] nums, int k) { int n = nums.length; List res = new ArrayList(); for (int i = 0; i < n - k + 1; i++) { int max = nums[i]; for (int j = 1; j < k; j++) { max = Math.max(max, nums[i + j]); } res.add(max); } int[] resultArray = res.stream().mapToInt(Integer::intValue).toArray(); return resultArray; } }
I am sure YOU know what you are talking about! You talk too quick and the whiteboard drawings are just a scrawl. I could not follow it. I get what you are trying to do about sliding to the right showing the next three numbers. Would have been nice if you also showed it in action. Very hard to watch. Talk slower and neaten up you writing. Again, you obviously know what you are on about.
EDIT: Space Complexity will be O(K) .
Done ✅✅
जय श्री राम बहना 🙏🏻🙏🏻
Didi aaj maine 4 video complete ki hai jo skip ho gye thi exam ki wajah se. Thank you so much Didi.😊 & Didi 😊 Jay shree Ram🙏
Keep going 😊
@@TechWithSaumya yes Didi 😊
Brute Force Approach
class Solution {
public int[] maxSlidingWindow(int[] nums, int k) {
int n = nums.length;
List res = new ArrayList();
for (int i = 0; i < n - k + 1; i++) {
int max = nums[i];
for (int j = 1; j < k; j++) {
max = Math.max(max, nums[i + j]);
}
res.add(max);
}
int[] resultArray = res.stream().mapToInt(Integer::intValue).toArray();
return resultArray;
}
}
I am sure YOU know what you are talking about! You talk too quick and the whiteboard drawings are just a scrawl. I could not follow it. I get what you are trying to do about sliding to the right showing the next three numbers. Would have been nice if you also showed it in action. Very hard to watch. Talk slower and neaten up you writing. Again, you obviously know what you are on about.