I googled about SIGSEGV and it said that make sure that you aren’t declaring too much memory or accessing an element which is out of bounds. But I can’t see either of that happening in my program(as of now).
Edit - Was thinking about some testcases and came to a conclusion that my older way of solving the problem would give wrong answer at some testcases, made some changes and wrote this instead.
Getting TLE now…