Find the minimal positive integer not occurring in a given sequence.
Solution
#include <unordered_map>int solution(vector<int> &A) { // write your code in C++11 (g++ 4.8.2) unordered_map<int, int> map; for (int i = 0; i < int(A.size()); i++) { if (A[i] > 0) { map[A[i]] = i; } } for (int i = 1; i < int(map.size() + 1); i++) { if (map.find(i) == map.end()) return i; } return int(map.size() + 1);}