I want to find taht array in the code whose sum is max i mean subarray of size t how to get ans i m getting run time error in the code
Just count the number of 0s and 2s then place all zeros at first , all 2s at last and left over elements at middle.
Your question which you asked to find the max subarray of size k can be done in 0(n) time complexity.
Initially try finding the sum of first k elements. Then for each subarray remove the value of first element from previous subarray and then add the value of next element into sum.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.