alternative for nested loops in c



if there any alternative for nested loops to reduce execution time?


different Algorithm.


that is what i asked sir,


You can come up with different alternatives for different questions.
For exempting loops, you need to think differently about the problem.
A good approach would be:

  1. Write down the possible test cases (mainly boundary cases).
  2. Write down the outputs for them that you get by simply solving the problem mathematically.
  3. Try finding out a relation between the noted inputs and their corresponding outputs (there definitely is one alternative if you’re getting TLE by naive approach).

Try this thing for the problem and you will hit a super simple relation between the inputs and outputs.