Problem in declaring vector,Runtime error

The link to my code is http://ideone.com/mwwBjl

Why am i getting runtime error. the above code is solution of question https://www.interviewbit.com/problems/smallest-multiple-with-0-and-1/

Thanks in advance.

the problem is in your multiple function not in declaration…
if you try to run your main only by commenting your multiple function you will see the output “in main”

on dev c++, I could even see some chk0 printed.chk0 which are before the assignment flag[val]=1 get printed and after that code stops working.

  1. Your multiple function returns an std::string but you haven’t used the return value. Though this is not the reason of the runtime error, still it will give a warning.

  2. In line number 16 and 18, you are doing flag[val] = 1, where val = 1 according to your code. However, your vectors are still of size 0, so you are accessing memory out of bounds, which gives you RTE.

Have a look at this code of yours. I have removed the RTE, but have not touched your solution: Corrected code

Got it. Thanks a lot.

//