Help me with problem Buy1-Get1

Problem Link:-
Solution link :-
Please guide me if my logic is correct as i am getting runtime error(SIGABRT) even if it is running well. Was my logic correct i.e, compromising time and space complexity would the program run on this logic?

Your logic is correct.
However you did not read the statement correctly.
The input string can contain a-z and A-Z.
Your code tries to access invalid array location (-ve) for A-Z hence it gives SIGABRT.

Fix this and it should work.

Thanks for your help