# Leetcode Constraints

I’ve been solving problems on leetcode from last couple of weeks or so and there is one thing about this platform that is really really frustrating which is NO CONSTRAINTS IN THE PROBLEMS

I always do problems looking at the constraints in codeforces, atcoder, codechef, hackerearth etc. Many times I write solution spending my time and suddenly there’s one test case where it fails like empty array or something which is still fine but not giving any constraints of the input absolutely at all make me slam my head on desk.

Today I was solving a hard problem and write the dp code for it in 35-40 mins. it passed all my test cases which I thought back then and then suddenly it gave me wrong answer because there were negative values in the array (-_-)

I mean i knew my logic would failed for negative values but only if they had written the constraints like a[i] can be negative, my 35-40 mins wouldn’t have been wasted in writing the flawed code.

I know its a good platform, no doubt about that but has anyone faced the similar issue while solving problems there?

2 Likes

Empty array constraint is so bad. At least they can mention it.

Also, time limt is never given.

Yes brother, thats really an issue. There is always one test case that has empty array and root NULL in case of tree problems. Dont feel demotivated or depressed. It is how it is, you will get used to it, it is indeed a good platform.

1 Like

Constraint sometimes limit your solution. Sometimes a solution can be solved in O(n) but with given constraints you solved it within O(n^2). I think their main motive is the efficient solution.

1 Like

In interview they generally ask you “will your code fail for any input”. If you’ve faced this empty array WA in leetcode, you can immediately answer them by saying that your code will fail for an empty array. Because in real world, an empty array being sent as a parameter is not entirely impossible. If you’ve noticed carefully, the empty array test cases are not added in the weekly contests. They are just there in practice problems.

3 Likes

Then they must designed test cases that the O(N^2) should not pass and I’m sure that they do because 90% of the time brute force don’t pass in medium or hard problems of leetcode. But they should give the constraints.

I’m completely wrong if I say don’t give negative numbers in array or whatsoever but at-least you can write it in the constraints something like- `-10^9 < a < 10^9` so that I design considering all the possibilities.

Not knowing the constraints at all is just like shooting in the dark, you don’t know where to shoot at all but knowing constraints is like you know where the flag is and now it depends on your skills and practice that you hit bull’s eye or not.

Possibly shooting in the dark helps you in the future where not to shoot.