Welcome to CP!
Well, first of all understand that the online judge accepts solutions if your code gives the correct output for the hidden test cases too, not only the sample ones that you see on the problem statement page. Try giving more time to debug your code (yeah, that can be really frustrating at times ), find the corner cases, learn about various types of approaches and algorithms, and optimise your code according to the given constraints, and simplify time complexity.
Coming to your special mention about TLE, it’s all because your program is too slow for the given inputs. That can just be solved by changing your approach and optimising (depnds on specific question and its constraints) the code.
You might want to go through the following to understand TLE:
You can always read editorials, they’ll really help you build your step-by-step approach. Participate in contests and practice problems according to the difficulty level that suits you. Also, the forum is always open for your genuine doubts and problems. We all are happy and willing to help you out in case you get stuck anywhere.
Happy coding!