Skip to content

Instantly share code, notes, and snippets.

@PeterStayPool
Created March 20, 2016 13:19
find max drop
#include <iostream>
using namespace std;
int find_max_drop(int* input, int len)
{
int max_drop = INT_MIN;
int max_pos = 0;
for(int i = 0; i < len; i++)
{
int diff = input[max_pos] - input[i];
if (max_drop < diff)
max_drop = diff;
if (input[max_pos] < input[i])
max_pos = i;
}
return max_drop;
}
int main()
{
int input[7] = {2,4,-1,5, 7,6, 1};
cout<<"max drop = "<<find_max_drop(input, 7)<<endl;
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment