I am submitting leetcode problem no 643. Maximum Average Subarray problem it is accepting but not submmitting [closed]

  c++, dynamic-programming, sliding-window

https://leetcode.com/problems/maximum-average-subarray-i/

class Solution {
public:
    double findMaxAverage(vector<int>& nums, int k) {
        
        double sum = 0.0;
        double mx = 0.0;
        
        int i = 0;
        int j = 0;
        
        while (j < nums.size())
        {
            sum = sum + nums[j];
            
            if(nums.size() == 1)
            {
                return nums[i];
            }
           
            if (j - i + 1 < k)
            {
                j++;
            }          
            else if (j - i + 1 == k)
            {           
                mx = max(mx , sum / k) ;
                sum = sum - nums[i];
        
                i++;
                j++;
            }
                                
        }
        return mx;
    }
};

Error :- https://leetcode.com/problems/maximum-average-subarray-i/submissions/

Source: Windows Questions C++

LEAVE A COMMENT