6 questions. Covers Maximum product subarray.
Questions 1 to 5 of 6
cpp #include <algorithm> #include <iostream> #include <vector> int main() { std::vector<long long> a = {-3, 2, -4}; long long best = a[0], curMax = a[0], curMin = a[0]; for (std::size_t i = 1; i < a.size(); ++i) { long long x = a[i]; long long newMax = std::max({x, curMax * x, curMin * x}); long long newMin = std::min({x, curMax * x, curMin * x}); curMax = newMax; curMin = newMin; best = std::max(best, curMax); } std::cout << best << "\n"; }
curMax = 8
curMin = -80
x = -4
curMax
[-5]
100000 * 100000 * 3
[2, 3, -2, 4]
5 question(s) left on this page.