Tasks Details
medium
Find the smallest positive integer that does not occur in a given sequence.
Task Score
100%
Correctness
100%
Performance
100%
This is a demo task.
Write a function:
int solution(vector<int> &A);
that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A.
For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5.
Given A = [1, 2, 3], the function should return 4.
Given A = [−1, −3], the function should return 1.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- each element of array A is an integer within the range [−1,000,000..1,000,000].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Solution
Programming language used C++
Total time used 26 minutes
Effective time used 26 minutes
Notes
not defined yet
Task timeline
Code: 13:07:53 UTC,
java,
autosave
Code: 13:07:56 UTC,
cpp,
autosave
Code: 13:09:23 UTC,
cpp,
verify,
result: Failed
Analysis
expand all
Example tests
1.
0.001 s
WRONG ANSWER,
got 1 expected 5
1.
0.001 s
WRONG ANSWER,
got 1 expected 4
1.
0.001 s
OK
Code: 13:09:42 UTC,
cpp,
verify,
result: Failed
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A) {
// write your code in C++14 (g++ 6.2.0)
}
User test case 1:
[1]
Analysis
expand all
Example tests
1.
0.001 s
WRONG ANSWER,
got 1 expected 5
1.
0.001 s
WRONG ANSWER,
got 1 expected 4
1.
0.001 s
OK
Code: 13:10:10 UTC,
cpp,
verify,
result: Failed
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A) {
return 5;
}
User test case 1:
[1]
Analysis
expand all
Example tests
1.
0.001 s
OK
1.
0.001 s
WRONG ANSWER,
got 5 expected 4
1.
0.001 s
WRONG ANSWER,
got 5 expected 1
Code: 13:10:40 UTC,
cpp,
autosave
Code: 13:10:53 UTC,
cpp,
autosave
Code: 13:11:12 UTC,
cpp,
autosave
Code: 13:11:33 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
bool is_positi
int solution(vector<int> &A) {
std::sort(A.begin(),a.end());
std::binary_search(A.begin(),a.end(),)
return 5;
}
Code: 13:11:57 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
bool is_positive(int a)
{
return a>0;
}
int solution(vector<int> &A) {
std::sort(A.begin(),a.end());
std::binary_search(A.begin(),a.end(),)
return 5;
}
Code: 13:12:03 UTC,
cpp,
verify,
result: Failed
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
bool is_positive(int a)
{
return a>0;
}
int solution(vector<int> &A) {
std::sort(A.begin(),a.end());
std::binary_search(A.begin(),a.end(),is_positive)
return 5;
}
Analysis
Compile error
func.cpp: In function 'int solution(std::vector<int>&)': func.cpp:13:25: error: 'a' was not declared in this scope std::sort(A.begin(),a.end()); ^ func.cpp:16:1: warning: no return statement in function returning non-void [-Wreturn-type] } ^
Code: 13:12:13 UTC,
cpp,
verify,
result: Failed
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
bool is_positive(int a)
{
return a>0;
}
int solution(vector<int> &A) {
std::sort(A.begin(),a.end());
std::binary_search(A.begin(),a.end(),is_positive);
return 5;
}
Analysis
Compile error
func.cpp: In function 'int solution(std::vector<int>&)': func.cpp:13:25: error: 'a' was not declared in this scope std::sort(A.begin(),a.end()); ^
Code: 13:12:25 UTC,
cpp,
verify,
result: Failed
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
bool is_positive(int a)
{
return a>0;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
std::binary_search(A.begin(),A.end(),is_positive);
return 5;
}
Analysis
Compile error
In file included from /opt/lang/gcc/include/c++/6.2.0/algorithm:62:0, from func.cpp:2: /opt/lang/gcc/include/c++/6.2.0/bits/stl_algo.h: In instantiation of 'bool std::binary_search(_FIter, _FIter, const _Tp&) [with _FIter = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _Tp = bool(int)]': func.cpp:14:53: required from here /opt/lang/gcc/include/c++/6.2.0/bits/stl_algo.h:2257:39: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] return __i != __last && !(__val < *__i); ~~~~~~~^~~~~~~ In file included from /opt/lang/gcc/include/c++/6.2.0/bits/stl_algobase.h:71:0, from /opt/lang/gcc/include/c++/6.2.0/bits/char_traits.h:39, from /opt/lang/gcc/include/c++/6.2.0/string:40, from solution.cpp:3: /opt/lang/gcc/include/c++/6.2.0/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_less_val::operator()(_Iterator, _Value&) const [with _Iterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _Value = bool(int)]': /opt/lang/gcc/include/c++/6.2.0/bits/stl_algobase.h:959:14: required from '_ForwardIterator std::__lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&, _Compare) [with _ForwardIterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _Tp = bool(int); _Compare = __gnu_cxx::__ops::_Iter_less_val]' /opt/lang/gcc/include/c++/6.2.0/bits/stl_algo.h:2255:22: required from 'bool std::binary_search(_FIter, _FIter, const _Tp&) [with _FIter = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _Tp = bool(int)]' func.cpp:14:53: required from here /opt/lang/gcc/include/c++/6.2.0/bits/predefined_ops.h:55:22: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] { return *__it < __val; } ~~~~~~^~~~~~~
Code: 13:16:41 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allpos(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it < 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
std::binary_search(A.begin(),A.end(),is_positive);
return 5;
}
Code: 13:16:54 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it < 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
std::binary_search(A.begin(),A.end(),is_positive);
return 5;
}
Code: 13:17:05 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
std::binary_search(A.begin(),A.end(),is_positive);
return 5;
}
Code: 13:17:35 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
if(allneg(A.begin(),))
return 5;
}
Code: 13:17:45 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
if(allneg(A.begin(),A.end())){
}
return 5;
}
Code: 13:17:55 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
if(allneg(A.begin(),A.end())){
return 1;
}
return 5;
}
Code: 13:17:56 UTC,
cpp,
verify,
result: Failed
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
if(allneg(A.begin(),A.end())){
return 1;
}
return 5;
}
User test case 1:
[1]
Analysis
Code: 13:18:23 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
if(allneg(A.begin(),A.end())){
return 1;
}
return 5;
}
Code: 13:18:53 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
if(std::binary_search(A.)
return 5;
}
Code: 13:19:04 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
if(std::binary_search(A.begin(),A.end(),v)
return 5;
}
Code: 13:19:35 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
if(std::binary_search(A.begin(),A.end(),v){
return 5;
}
Code: 13:19:45 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
if(std::binary_search(A.begin(),A.end(),v){
}
return 5;
}
Code: 13:20:32 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
if(std::binary_search(A.begin(),A.end(),v){
v++
}
return 5;
}
Code: 13:20:45 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
if(std::binary_search(A.begin(),A.end(),v){
v++
} else {
return v;
}
return 5;
}
Code: 13:21:00 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
if(std::binary_search(A.begin(),A.end(),v){
v++
} else {
return v;
}
return ;
}
Code: 13:21:17 UTC,
cpp,
verify,
result: Failed
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
if(std::binary_search(A.begin(),A.end(),v){
v++
} else {
return v;
}
return v;
}
Analysis
Compile error
func.cpp: In function 'int solution(std::vector<int>&)': func.cpp:23:47: error: expected ')' before '{' token if(std::binary_search(A.begin(),A.end(),v){ ^ func.cpp:29:1: warning: control reaches end of non-void function [-Wreturn-type] } ^
Code: 13:22:00 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
if(std::binary_search(A.begin(),A.end(),v)){
v++
} else {
return v;
}
return v;
}
Code: 13:22:02 UTC,
cpp,
verify,
result: Failed
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
if(std::binary_search(A.begin(),A.end(),v)){
v++
} else {
return v;
}
return v;
}
Analysis
Compile error
func.cpp: In function 'int solution(std::vector<int>&)': func.cpp:25:5: error: expected ';' before '}' token } else { ^
Code: 13:22:13 UTC,
cpp,
verify,
result: Failed
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
if(std::binary_search(A.begin(),A.end(),v)){
v++;
} else {
return v;
}
return v;
}
User test case 1:
[1]
Analysis
expand all
Example tests
1.
0.001 s
WRONG ANSWER,
got 2 expected 5
1.
0.001 s
WRONG ANSWER,
got 2 expected 4
1.
0.001 s
OK
Code: 13:23:04 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
if(std::binary_search(A.begin(),A.end(),v)){
v++;
} else {
return v;
}
return v;
}
Code: 13:23:34 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
for(size_t i = 0; i < A.size(); i++) {
std::Cout
}
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
if(std::binary_search(A.begin(),A.end(),v)){
v++;
} else {
return v;
}
return v;
}
Code: 13:23:47 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
for(size_t i = 0; i < A.size(); i++) {
std::cout << i << ", ";
}
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
if(std::binary_search(A.begin(),A.end(),v)){
v++;
} else {
return v;
}
return v;
}
Code: 13:23:56 UTC,
cpp,
verify,
result: Failed
// you can use includes, for example:
#include <algorithm>
#include <iostream>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
for(size_t i = 0; i < A.size(); i++) {
std::cout << i << ", ";
}
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
if(std::binary_search(A.begin(),A.end(),v)){
v++;
} else {
return v;
}
return v;
}
User test case 1:
[1]
Analysis
expand all
Example tests
1.
0.001 s
WRONG ANSWER,
got 2 expected 5
stdout:
0, 1, 2, 3, 4, 5,
1.
0.001 s
WRONG ANSWER,
got 2 expected 4
stdout:
0, 1, 2,
1.
0.001 s
OK
stdout:
0, 1,
Code: 13:24:16 UTC,
cpp,
verify,
result: Failed
// you can use includes, for example:
#include <algorithm>
#include <iostream>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
for(size_t i = 0; i < A.size(); i++) {
std::cout << A[i] << ", ";
}
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
if(std::binary_search(A.begin(),A.end(),v)){
v++;
} else {
return v;
}
return v;
}
User test case 1:
[1]
Analysis
expand all
Example tests
1.
0.001 s
WRONG ANSWER,
got 2 expected 5
stdout:
1, 1, 2, 3, 4, 6,
1.
0.001 s
WRONG ANSWER,
got 2 expected 4
stdout:
1, 2, 3,
1.
0.001 s
OK
stdout:
-3, -1,
Code: 13:27:41 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
#include <iostream>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
for(size_t i = 0; i < A.size(); i++) {
std::cout << A[i] << ", ";
}
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
if(std::binary_search(A.begin(),A.end(),v)){
v++;
} else {
return v;
}
return v;
}
Code: 13:27:51 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
#include <iostream>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
for(size_t i = 0; i < A.size(); i++) {
std::cout << A[i] << ", ";
}
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
for
if(std::binary_search(A.begin(),A.end(),v)){
v++;
} else {
return v;
}
return v;
}
Code: 13:28:21 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
#include <iostream>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
for(size_t i = 0; i < A.size(); i++) {
std::cout << A[i] << ", ";
}
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
if(std::binary_search(A.begin(),A.end(),v)){
v++;
} else {
return v;
}
return v;
}
Code: 13:28:51 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
#include <iostream>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
for(size_t i = 0; i < A.size(); i++) {
std::cout << A[i] << ", ";
}
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
auto it = A.begin();
while(it!=A.end()){
if(std::binary_search(it,A.end(),v)){
v++;
} else {
return v;
}
}
return v;
}
Code: 13:29:09 UTC,
cpp,
verify,
result: Passed
// you can use includes, for example:
#include <algorithm>
#include <iostream>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
for(size_t i = 0; i < A.size(); i++) {
std::cout << A[i] << ", ";
}
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
auto it = A.begin();
while(it!=A.end()){
if(std::binary_search(it,A.end(),v)){
v++;
} else {
return v;
}
it++;
}
return v;
}
User test case 1:
[1]
Analysis
expand all
Example tests
1.
0.001 s
OK
stdout:
1, 1, 2, 3, 4, 6,
1.
0.001 s
OK
stdout:
1, 2, 3,
1.
0.001 s
OK
stdout:
-3, -1,
Code: 13:29:27 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
#include <iostream>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
for(size_t i = 0; i < A.size(); i++) {
std::cout << A[i] << ", ";
}*/
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
auto it = A.begin();
while(it!=A.end()){
if(std::binary_search(it,A.end(),v)){
v++;
} else {
return v;
}
it++;
}
return v;
}
Code: 13:29:32 UTC,
cpp,
verify,
result: Passed
// you can use includes, for example:
#include <algorithm>
#include <iostream>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
std::sort(A.begin(),A.end());
/*
for(size_t i = 0; i < A.size(); i++) {
std::cout << A[i] << ", ";
}*/
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
auto it = A.begin();
while(it!=A.end()){
if(std::binary_search(it,A.end(),v)){
v++;
} else {
return v;
}
it++;
}
return v;
}
User test case 1:
[1]
Analysis
Code: 13:30:03 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
#include <iostream>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
i
std::sort(A.begin(),A.end());
/*
for(size_t i = 0; i < A.size(); i++) {
std::cout << A[i] << ", ";
}*/
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
auto it = A.begin();
while(it!=A.end()){
if(std::binary_search(it,A.end(),v)){
v++;
} else {
return v;
}
it++;
}
return v;
}
Code: 13:30:13 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
#include <iostream>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
if(A.empty)
std::sort(A.begin(),A.end());
/*
for(size_t i = 0; i < A.size(); i++) {
std::cout << A[i] << ", ";
}*/
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
auto it = A.begin();
while(it!=A.end()){
if(std::binary_search(it,A.end(),v)){
v++;
} else {
return v;
}
it++;
}
return v;
}
Code: 13:30:44 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
#include <iostream>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
if(A.empty()) throw
std::sort(A.begin(),A.end());
/*
for(size_t i = 0; i < A.size(); i++) {
std::cout << A[i] << ", ";
}*/
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
auto it = A.begin();
while(it!=A.end()){
if(std::binary_search(it,A.end(),v)){
v++;
} else {
return v;
}
it++;
}
return v;
}
Code: 13:30:57 UTC,
cpp,
verify,
result: Failed
// you can use includes, for example:
#include <algorithm>
#include <iostream>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
if(A.empty()) throw std::exception("unexpected");
std::sort(A.begin(),A.end());
/*
for(size_t i = 0; i < A.size(); i++) {
std::cout << A[i] << ", ";
}*/
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
auto it = A.begin();
while(it!=A.end()){
if(std::binary_search(it,A.end(),v)){
v++;
} else {
return v;
}
it++;
}
return v;
}
Analysis
Compile error
func.cpp: In function 'int solution(std::vector<int>&)': func.cpp:19:52: error: no matching function for call to 'std::exception::exception(const char [11])' if(A.empty()) throw std::exception("unexpected"); ^ In file included from /opt/lang/gcc/include/c++/6.2.0/new:40:0, from /opt/lang/gcc/include/c++/6.2.0/ext/new_allocator.h:33, from /opt/lang/gcc/include/c++/6.2.0/x86_64-pc-linux-gnu/bits/c++allocator.h:33, from /opt/lang/gcc/include/c++/6.2.0/bits/allocator.h:46, from /opt/lang/gcc/include/c++/6.2.0/string:41, from solution.cpp:3: /opt/lang/gcc/include/c++/6.2.0/exception:63:5: note: candidate: std::exception::exception() exception() _GLIBCXX_USE_NOEXCEPT { } ^~~~~~~~~ /opt/lang/gcc/include/c++/6.2.0/exception:63:5: note: candidate expects 0 arguments, 1 provided /opt/lang/gcc/include/c++/6.2.0/exception:60:9: note: candidate: constexpr std::exception::exception(const std::exception&) class exception ^~~~~~~~~ /opt/lang/gcc/include/c++/6.2.0/exception:60:9: note: no known conversion for argument 1 from 'const char [11]' to 'const std::exception&'
Code: 13:32:29 UTC,
cpp,
autosave
// you can use includes, for example:
#include <algorithm>
#include <iostream>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
if(A.empty()) throw std::invalid_argument("unexpected");
std::sort(A.begin(),A.end());
/*
for(size_t i = 0; i < A.size(); i++) {
std::cout << A[i] << ", ";
}*/
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
auto it = A.begin();
while(it!=A.end()){
if(std::binary_search(it,A.end(),v)){
v++;
} else {
return v;
}
it++;
}
return v;
}
Code: 13:32:35 UTC,
cpp,
verify,
result: Passed
// you can use includes, for example:
#include <algorithm>
#include <iostream>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
if(A.empty()) throw std::invalid_argument("unexpected empty vector");
std::sort(A.begin(),A.end());
/*
for(size_t i = 0; i < A.size(); i++) {
std::cout << A[i] << ", ";
}*/
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
auto it = A.begin();
while(it!=A.end()){
if(std::binary_search(it,A.end(),v)){
v++;
} else {
return v;
}
it++;
}
return v;
}
User test case 1:
[1]
Analysis
Code: 13:32:56 UTC,
cpp,
verify,
result: Passed
// you can use includes, for example:
#include <algorithm>
#include <iostream>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
if(A.empty()) throw std::invalid_argument("unexpected empty vector");
std::sort(A.begin(),A.end());
/*
for(size_t i = 0; i < A.size(); i++) {
std::cout << A[i] << ", ";
}*/
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
auto it = A.begin();
while(it!=A.end()){
if(std::binary_search(it,A.end(),v)){
v++;
} else {
return v;
}
it++;
}
return v;
}
User test case 1:
[1]
Analysis
Code: 13:32:59 UTC,
cpp,
final,
score: 
100
// you can use includes, for example:
#include <algorithm>
#include <iostream>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
template <class T>
bool allneg(const T start, const T end) {
T it;
for (it = start; it != end; it++) {
if (*it >= 0) return false;
}
return true;
}
int solution(vector<int> &A) {
if(A.empty()) throw std::invalid_argument("unexpected empty vector");
std::sort(A.begin(),A.end());
/*
for(size_t i = 0; i < A.size(); i++) {
std::cout << A[i] << ", ";
}*/
if(allneg(A.begin(),A.end())){
return 1;
}
int v = 1;
auto it = A.begin();
while(it!=A.end()){
if(std::binary_search(it,A.end(),v)){
v++;
} else {
return v;
}
it++;
}
return v;
}
Analysis summary
The solution obtained perfect score.
Analysis
Detected time complexity:
O(N) or O(N * log(N))
expand all
Correctness tests
1.
0.001 s
OK
2.
0.001 s
OK
3.
0.001 s
OK
4.
0.001 s
OK
1.
0.001 s
OK
2.
0.001 s
OK
3.
0.001 s
OK
1.
0.001 s
OK
2.
0.001 s
OK
1.
0.001 s
OK
2.
0.001 s
OK
1.
0.001 s
OK
expand all
Performance tests
1.
0.001 s
OK
2.
0.001 s
OK
3.
0.004 s
OK
1.
0.012 s
OK
1.
0.016 s
OK
2.
0.012 s
OK
1.
0.008 s
OK