The max product of consecutive elements in an array

后端 未结 8 1509
面向向阳花
面向向阳花 2021-01-30 03:13

I was asked this algorithm question during my onsite interview. Since I was not asked to sign NDA, I post it here for an answer.

Given an array of REAL

8条回答
  •  猫巷女王i
    2021-01-30 04:05

    Taking care of the thing if there are no 1's in the array and the product coming should not be 1 in that case. Here is my code:

    #include
    using namespace std;
    
    int max(int x, int y)
    { return (y > x)? y : x; }
    int min(int x, int y)
    { return (y < x)? y : x; }
    bool search(int a[],int k,int n)
    {
        for(int i=0;i0)
            {
                maxpos=maxpos*a[i];
                minneg=min(minneg,minneg*a[i]);
            }
            if(pro_max

提交回复
热议问题