I am not accessing any index out of bounds but then still I am encountering runtime error on test for the below , it will be helpful if someone points out the reason for this , below I am attaching the link for the source code
You sound very sure of yourself …
Anyway: index out-of-bounds on the sample test input:
[simon@simon-laptop][05:05:55]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh
Compiling msatanzeel-blah2.cpp
Executing command:
g++ -std=c++17 msatanzeel-blah2.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv
Successful
[simon@simon-laptop][05:06:24]
[~/devel/hackerrank/otherpeoples]>cat 1593E-sample-test-input.txt
6
14 1
1 2
2 3
2 4
4 5
4 6
2 7
7 8
8 9
8 10
3 11
3 12
1 13
13 14
2 200000
1 2
3 2
1 2
2 3
5 1
5 1
3 2
2 1
5 4
6 2
5 1
2 5
5 6
4 2
3 4
7 1
4 3
5 1
1 3
6 1
1 7
2 1
[simon@simon-laptop][05:06:32]
[~/devel/hackerrank/otherpeoples]>cat 1593E-sample-test-input.txt | ./a.out
/usr/include/c++/7/debug/vector:417:
Error: attempt to subscript container with out-of-bounds index 7, but
container only holds 3 elements.
Objects involved in the operation:
sequence "this" @ 0x0x55da14de5780 {
type = std::__debug::vector<int, std::allocator<int> >;
}
Aborted (core dumped)
I understand that there’s some place where the code is accessing out of bounds,but can you specify where is it
1 Like
This line:
if (par[ele] != -1 && s2.find(par[ele]) == s2.end())
1 Like