more katas

This commit is contained in:
2019-12-09 11:49:52 +01:00
parent aa223cf1c5
commit 97c0e43874
4 changed files with 105 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int maxProduct (vector<int>numbers , int sub_size)
{
// Sort numbers
std::sort(numbers.begin(), numbers.end());
int result = 1;
// Loop over last sub_size elements
for(auto ptr = numbers.end()-1; ptr >= numbers.end() - sub_size; ptr--){
result *= *ptr;
}
return result;
}
int main(){
std::vector<int> numbers = {1,2,3,4,5};
std::cout << maxProduct(numbers, 3);
}