aboutsummaryrefslogtreecommitdiff
path: root/challenge-080/adam-russell/cpp/ch-1.cpp
blob: c13f1c8c43088e4c533776c44c3688c8d4f1a4ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>    
#include <algorithm>    
#include <vector>       
/*
* You are given an unsorted list of integers @N.
* Write a script to find out the smallest positive number missing.
*/
int least_missing(int n[]){
    std::sort (n, n + 4);
    std::vector<int> numbers (n, n + 4);  
    for(int i = n[0]; i < n[3]; i++){
        std::vector<int>::iterator itr = std::find(numbers.begin(), numbers.end(), i);
        if (itr == std::end(numbers)) {
            if(i > 0)
                return i;
        }
    }
    return -1;
}

int main(int argc, char** argv){
    int N[4] = {5, 2, -2, 0};
    int i = least_missing(N);
    std::cout << "the least positive missing number is " << i << std::endl;
}