Skip to content

Bug Report for buy-and-sell-crypto #4725

@Mitohondriyaa

Description

@Mitohondriyaa

Bug Report for https://neetcode.io/problems/buy-and-sell-crypto

Hello! I noticed that the following solution works correctly on all test cases:

class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int result = 0;
        int l = 0, r = 1;

        while (r < prices.size()) {
            result = max(result, prices[r] - prices[l]);

            if (prices[l] > prices[r]) {
                l = r;
            }
            
            r++;
        }
    }
};

Please add test case [3, 4, 1]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions