Maximum Product Subarray Algorithm

Each of the RF technology offers a distinct trade-off between price, frequency, gain, large-scale integration, lifetime, linearity, noise figure, packaging, power handling, power consumption, reliability, ruggedness, size, supply voltage, switching time and weight. Besides RF MEMS technology, III-V compound semiconductor (GaAs, GaN, InP, InSb), ferrite, ferroelectric, silicon-based semiconductor (RF CMOS, SiC and SiGe), and vacuum tube technology are available to the RF designer.
class Solution {
public:
    int maxProduct(int A[], int n) {
        if (n == 0) {
            return 0;
        }
        int result = A[0];
        int premax = A[0];
        int premin = A[0];
        for (int i = 1; i < n; i++) {
            int heremax = max(A[i], max(A[i] * premax, A[i] * premin));
            int heremin = min(A[i], min(A[i] * premax, A[i] * premin));
            result = max(result, heremax);
            premax = heremax;
            premin = heremin;
        }
        return result;
    }
};

LANGUAGE:

DARK MODE: