Why this code is showing runtime error?
Read the constraints carefully:
The first line contains a single integer T <= 40, the number of test cases. T test cases follow. The only line of each test case contains a non-empty text composed only of uppercase letters of English alphabet. The length of the text is less then 100. There are no any spaces in the input.
As it is clearly mentioned length of the text is less than 100 so you have to make an array of size 100, where as you made the array of size 50.
Remember SIGSEGV RE is thrown when data tries to access more memory than allocated and same is happening in your code.
You may see here i just updated the size from 50 to 100 and your code passed:
remember always read the constraints carefully…