Easiest and optimized O(N) solution
\nclass Solution {\npublic:\n    int maxProfit(vector<int>& profit) {\n        int ans = profit[0];\n        int mxpro = -1;\n        for(int i = 0 ; i < profit
```\nclass Solution {\npublic:\n    int maxProfit(vector<int>& profit) {\n        int ans = profit[0];\n        int mxpro = -1;\n        for(int i = 0 ; i < profit.size() ; i++){\n            ans = min(ans,profit[i]);\n            mxpro = max(mxpro , profit[i] - ans);\n        }\n        return mxpro;\n    }\n};\n```
['C']