I am trying to store key-value in a STL map/unordered map
N = 10^5 and Ai =10^9
It gives SIGABRT, why?
Solution to problem Stacks, contest 4,DSA learning series
Impossible to say without seeing your code; please either post it (formatted, please :)) or - even better! - link to your submission
1 Like
It’s easy to trigger Undefined Behaviour in this solution; consider the test input:
1
2
1 1
This gives:
[simon@simon-laptop][15:55:15]
[~/devel/hackerrank/otherpeoples]>echo "1
2
1 1
" | ./a.out
/usr/include/c++/7/debug/set.h:348:
Error: attempt to erase from container with a past-the-end iterator.
Objects involved in the operation:
sequence "this" @ 0x0x7ffc3c361bf0 {
type = std::__debug::set<long, std::less<long>, std::allocator<long> >;
}
iterator "__position" @ 0x0x7ffc3c361b60 {
type = __gnu_debug::_Safe_iterator<std::_Rb_tree_const_iterator<long>, std::__debug::set<long, std::less<long>, std::allocator<long> > > (mutable iterator);
state = past-the-end;
references sequence with type 'std::__debug::set<long, std::less<long>, std::allocator<long> >' @ 0x0x7ffc3c361bf0
}
Aborted (core dumped)
1 Like
Thank you very much, got it!
I wonder why I couldn’t spot it.
1 Like