Https://practice.geeksforgeeks.org/problems/permutation-with-spaces/0

i have solved this question given in link , i am getting runtime for second case ABC , but output is correct for AB, can you check?