Embercode
✕
Dynamic ProgrammingQuick quiz

Maximum product

6 questions. Covers Maximum product subarray.

Questions 1 to 5 of 6

  1. 1. What does this program print? ``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"; } ``
  2. 2. The running values before a step are curMax = 8 and curMin = -80. The next value is x = -4. What is the new curMax?
  3. 3. True or false: for the list [-5], the answer is 0, because a zero can always be chosen.
  4. 4. The program multiplies 100000 * 100000 * 3. Which type does the lesson say to use for products, and why?
  5. 5. True or false: keeping only the largest running product gives the correct answer for the list [2, 3, -2, 4].

5 question(s) left on this page.