Skip to content

Bug Report for max-water-container #4415

@YatFungLoo

Description

@YatFungLoo

Bug Report for https://neetcode.io/problems/max-water-container

Accessing out of bound answer accepted only as test case, shows different Your Output:

With following implementation:

class Solution {
public:
    int maxArea(vector<int>& heights) {
        if (heights.size() <= 1) return 0;
        int i = 0, j = heights.size(), max_vol = 0;  // accessing out of bound j should be size - 1
        while (i < j) {
            int curr = min(heights[i], heights[j]) * (j - i);
            max_vol = max(curr, max_vol);
            if (heights[i] < heights[j]) {
                i++;
            } else {
                j--;
            }
        }
        return max_vol;
    }
};

The input case: height=[1,7,2,5,12,3,500,500,7,8,4,7,3,6]: submitting shows incorrect answer Your Output: 744, while using input as test case is accepted Your Output: 500.

Image Image

PS: Much appreciated for your website.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions