@@ -103,8 +103,8 @@ function maxSubarrayOfSizeK(arr, k) {
103
103
return maxSum
104
104
}
105
105
106
- max_sub_array_of_size_k (3 , [2 , 1 , 5 , 1 , 3 , 2 ])// 9
107
- max_sub_array_of_size_k (2 , [2 , 3 , 4 , 1 , 5 ])// 7
106
+ maxSubarrayOfSizeK (3 , [2 , 1 , 5 , 1 , 3 , 2 ])// 9
107
+ maxSubarrayOfSizeK (2 , [2 , 3 , 4 , 1 , 5 ])// 7
108
108
````
109
109
- Time complexity will be ` O(N*K) ` , where ` N ` is the total number of elements in the given array
110
110
@@ -313,10 +313,17 @@ function totalFruit (fruits) {
313
313
return windowMax
314
314
};
315
315
316
- totalFruit ([3 ,3 ,3 ,1 ,2 ,1 ,1 ,2 ,3 ,3 ,4 ])// 5
317
- totalFruit ([1 ,2 ,1 ])// 3,We can pick from all 3 trees.
318
- totalFruit ([0 ,1 ,2 ,2 ])// 3,We can pick from trees [1,2,2].If we had started at the first tree, we would only pick from trees [0,1].
319
- totalFruit ([1 ,2 ,3 ,2 ,2 ])// 4,We can pick from trees [2,3,2,2]. If we had started at the first tree, we would only pick from trees [1,2].
316
+ totalFruit ([3 ,3 ,3 ,1 ,2 ,1 ,1 ,2 ,3 ,3 ,4 ])
317
+ // 5
318
+
319
+ totalFruit ([1 ,2 ,1 ])
320
+ // 3,We can pick from all 3 trees.
321
+
322
+ totalFruit ([0 ,1 ,2 ,2 ])
323
+ // 3,We can pick from trees [1,2,2].If we had started at the first tree, we would only pick from trees [0,1].
324
+
325
+ totalFruit ([1 ,2 ,3 ,2 ,2 ])
326
+ // 4,We can pick from trees [2,3,2,2]. If we had started at the first tree, we would only pick from trees [1,2].
320
327
````
321
328
### Map Object Solution
322
329
```` js
0 commit comments