I was practising from 2-3 months by ignoring constraints because i didnt knew much but i saw in coding ninjas that constraints are very helpful to decide a solution time complexity so my confusion is if the constraint lets say is n>10^8 so i should design algorithm of O(log n) that is binary search stuffs??please correct me if i am wrong and please tell that how to deal with constraint(i am a beginner so tell me in easy manner)…Also how to approach a problem??i often spend 5-6 hrs thinking of a problem and after the editorial comes the pre-requisites are sets,greedy etc which i havent studied yet…please help how to approach a problem!!please
I am a Newbie too , i never took any course i keep on solving problems , More WA i give more i learn , after solving good number of problems you will get familiar with Constraints and Approaches
For constraints,think 10^8 is around 1 sec so like that according to value you can calculate if it will stay in time limits or not.
And if you are not able to solve a problem for 30-40 minutes as a beginner then just leave it and move to the editorial.If you understand the editorial then start coding it but if a prerequisite is there , then try to learn it.
It’s not difficult,just keep practicing
PS: There are some good video solutions,refer them also.
1 sec approx 10^7 or 10^8 operations, so O(N) passes.
If constraints are 10^18 then O(logN) passes.
If constraints are 10^5 or 10^6 then O(NlogN) passes, though it also depends on question like in some question they also give test cases till 10^3 or 10^4, so need to observe this also.
But generally the above holds true.
but this would work when i practice i can see the editorials like even after 2hrs trying but specially in contests when i approach a problem how would i know that this problem is out of my league or its something that i havent studied??like if the pre-requisite is euclids gcd but i havent studied that so if i spent 2 hours on that question without knowing that this should be applied here then 2 hrs would be wasted right?so how to actually approach a problem?and by seeing constraints like 10^9 should i think of binary search?i mean that by judging constraints we have to frame algos?
after reading q you have to see constraint.it will decide which approach we should take suppose n is very(100) low so we can go n^2 also.if n is 10^18 then we are assured that even n will not work so we have to go for log(n).
so if we decide and find that O(log n) is working so do we need to think only of the algos that use O(log n) exmaple binary search?