What I Learned from Solving 100 HackerRank Problems
I started HackerRank in November 2020 during college for coding practice. After 2 years and 100+ solved problems, here is what I learned, and what I wish I’d known at problem one. 1. Reading the problem carefully is half the solution Many of my failed submissions came from misreading the input format, the constraints, or the expected output, not from wrong logic. Now I read the sample input and output first, then the constraints, then the description. 2. Constraints tell you which approach will work The Array Manipulation problem showed this clearly. My first solution looped through every range for every query. It worked on small inputs and timed out on large ones. The fix was to record only the start and end of each range, then add everything up in one pass: def arrayManipulation(n, queries): diff = [0] * (n + 2) for a, b, k in queries: diff[a] += k diff[b + 1] -= k best = cur = 0 for x in diff: cur += x best = max(best, cur) ...