4

I am very much new to the time complexity practically although I know this concept very well theoretically, while I was searching practice problems on leetcode I came across about Constraints, I do not know how these constraints work practically in a simple java coding program, let's say I have a two sum problem at leetcode what does these marked constrains mean in the pic below

enter image description here

Your help would really be appreciated pls help and guide how these constraints work and what do these constraints meen in this two sum problem?

Thanks in advance

2
  • 2
    This shows the specified number ranges the test input can have. For example, numbers in the nums[i] can be in the range from -1000000000 to 1000000000. Your program has to be able to work with all numbers in the specified range. This has nothing to do with time complexity. Commented Jul 26, 2022 at 11:29
  • that depends on the problem, for this particular one: nums.length => 2 - you do not need to care about invalid input; abs(target) <= 10^9 - you do not need to care about integer overflow (i.e. only algorithm makes sense). Small numbers or "input contains lowercase english letters only" may give you idea to use primitive array instead of set/map or do not think about unicode symbols. Commented Jul 26, 2022 at 11:40

2 Answers 2

5

The constraints essentially give you information about what range of data you are working with, because lets say you have data of a very large range then you have to allocate more memory for it,eg. you have to use long int to store a particular value because its longer than 4 bytes in the internal storage, and thus the constraints give you the edge cases for the range of data you might be working with, but this also form problem to problem.

Sign up to request clarification or add additional context in comments.

Comments

0

The time and space that your algorithm will need while solving particular problem is what really matter , so as much as possible your algorithm need to be processed in the small amount of time and also need small space , so in the leetCode you need follow that particular constraint they provided , the range of which your algorithm work on , so in order to make it that constraint , use some sort Math.pow method in java , and use ** operator in python then use relational operator....

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.