K-Foldable String doubt

Question - CodeChef: Practical coding for everyone
My solution - LJgGfi - Online C++0x Compiler & Debugging Tool - Ideone.com

I tested my code for many test cases but i don’t know why runtime error is coming.

Plz help

[simon@simon-laptop][06:16:31]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh 
Compiling a_r_y_a_n-KFOLD.cpp
+ g++ -std=c++14 a_r_y_a_n-KFOLD.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv
a_r_y_a_n-KFOLD.cpp: In function ‘int main()’:
a_r_y_a_n-KFOLD.cpp:14:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<str.length();i++){
                     ~^~~~~~~~~~~~~
+ set +x
Successful
[simon@simon-laptop][06:16:38]
[~/devel/hackerrank/otherpeoples]>echo "1                 
10 10
1111111111
" | ./a.out
/usr/include/c++/7/bits/basic_string.h:1057: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator[](std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference = char&; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]: Assertion '__pos <= size()' failed.
Aborted (core dumped)
4 Likes

@ssjgz Is there some error in my code?
I didn’t got that.

It says that __pos<=size() failed. As in, you have used a out of bound index on a string, as it is part of the struct basic_string.

2 Likes

Thanks @everule1.
I got my mistake and corrected my code.

1 Like