There are times when I want to predict the time complexity or space complexity of the algorithm and want to check whether it fits into the given constraints or not. I have the doubt that sometimes it is given that the problems need to solve in a time limit of 1 or 2 seconds and the memory limit of 256 Megabytes or 512 Megabytes. In each of those cases, 1. What should be the maximum size of the array that we can declare? 2. When we need to use the array or the set. 3. Which time complexity fits best into the given constraints. 4. In case of double for loop. How do we need to access the matrix (generally in DP problems) to make sure that it will not exceed the time limit?
i.e (CSES Problem TLE Code: https://cses.fi/paste/c63f02b96710bdd1164250/
)
5) How to use the Modulo operator effectively to reduce the time complexity?
I need help to understand the exact mathematics behind the calculation of time and space.