One of the main reasons for timeout is that the algorithm time complexity is too high. In this case, you should choose a reasonable data structure to reduce the time complexity of your program, or change the algorithm. Each question we have done has a time limit, usually 1000 MS, that is, 1 second, there are also 2 seconds, 5 seconds, 10 seconds. The data scope of each question is described in advance, for example, n <= 100000. If your program has a for loop for n times, the number of operations is 10 ^ 6, and your program has two layers of nested for loop, each layer loops n times, and the number of operations is at least n * n, that is, 10 ^ 12. Generally, the number of operations in a computer within one second is about 10 ^ 7 to 10 ^ 8. Therefore, it is clear that the algorithm that loops n times can run within one second, the n * n loop algorithm cannot be completed within 1 second. Therefore, by estimating the time complexity of your program, adding the data range and time limit given by the question, you can probably determine whether your program has timed out. For more information about time complexity, see Introduction to algorithms.