Constraints

Constraints are, as you said, the LIMITS (Upper and Lower) of the input data, and are VERY important when considering the solution of a problem. They give an idea of the data types to be used, approach to be adopted etc.

Eg-

Lets say input constraint of an integer n is 10^15. (10 raised to power 15)

This means that-

1)Using int to store the data will result in overflow (Here it hinted on data type to be used)

  1. If you think of creating an array of this size, you’d exceed memory limit of code and hence arrays cannot be used (here it ruled out any approach using arrays)

  2. With n this large (if its something we have to iterate over), a nested loop or anything using slower algo like O(n^2) will usually give TLE (exceed time limit. Since operations to be performed are a lot)

And many more! You’d get the idea as you progress and practie!

Hope it helped, happy coding! :slight_smile:

9 Likes