diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..554158d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.21) +project(smallest_int) + +set(CMAKE_CXX_STANDARD 14) + +add_executable(smallest_int main.cpp) diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..bbf168a --- /dev/null +++ b/main.cpp @@ -0,0 +1,45 @@ +#include + +// you can use includes, for example: +// #include +#include +#include +#include + +constexpr size_t N_MAX_ELEMS = 1000000; + +// you can write to stdout for debugging purposes, e.g. +// cout << "this is a debug message" << endl; + +int solution(std::vector A) { + + std::vector ref(N_MAX_ELEMS/sizeof(uint64_t), 0); + + for (auto elem : A) { + if (elem <= 0) { + continue; + } + ref[elem/8] |= (1 << (elem%8)); + } + + for (size_t i = 0; i < ref.size(); i++) { + if (ref[i] != std::numeric_limits::max()) { + for (size_t j = 0; j < sizeof(uint64_t); j++) { + if (i == 0 && j == 0) { + continue; + } + if ((ref[i]&(1 << j))==0) { + return (i*8+j); + } + } + } + } + + return N_MAX_ELEMS+1; +} + + +int main() { + std::cout << solution({1,3,4,5,1,6}) << std::endl; + return 0; +}