Can anybody help me where I am wrong

My code

https://www.codechef.com/viewsolution/37001915

Link to problem

This code is giving you a runtime error because in the case of RLU when you count(“D”) it doesn’t exist. Further using count inside the while loop is a terrible idea it will give an TLE for sure. Use counter from collections or maintain a hashmap(dict in python) outside the loop for better complexity