general ideas for what I notice and feel while solving a problem
the solution is not the code, implementation is not the challenge here ( well not at this stage ). what I’m doing is more maths than code and it’s the right way to solve the maths aspect first in a stage of infinite memory and infinite ops AND refine it withing maps and ONLY THEN get to the implementational trickey and cleverness
trying to do both will have you spacing out
when doing maths — DEFINE CLEARLY and write LEGIBLY, that alone will make the next idea half obvious use notation to keep it concise but DO NOT drop info
- Performed in four split time tracked sequence.
Steps
- Read and simplify problem (may be done mentally for simpler problems). Must be done fully on any hint of difficulty.
- Constraints, sample tests are part of problem statement.
- Move to steps for default+problem type
Default
- Do not sit blindly. Try any approach that comes to find and see where it goes wrong.
- Write (rather type so it remains separate) all assertions that you make separately and clearly. Double check to ensure that any of assertions are not wrong. This is critical to solutions based on properties of optimal solution.
- Read the above point again. Verify your assertions. Your assertions are wrong.
- Wonder why the problem is framed as such. Why only 3 distinct? Why such an n? Why this test case?
- Do not get stuck on an idea. If you cannot find a solution with the current idea. Chances are that the solution is different.
- Read the code that you are writing.
- Do not start with the exotic approaches first. Unless its a high level algo that gives a direct solution to a low level problem. I mean exotic solutions that you thought up yourself. If you have never encountered such a solution earlier, chances are it does not work or is not as good as you though it to be.
- Brute force answers and see patters and try to guess a solution.
Constructive
- Try building a solution based on parity.
- If odd even does not work, try expressing as %4 as in 4k+1,4k+2,4k+3,4k.
- Properties of the optimal solution.
- Try the simpler random idea. Even more simple. More.
- Default 0
Greedy
- Properties of the optimal solution.
Math
- Just do everything very very very slowly but correctly and completely.
- In case of an unknown wrong answer, like really really unknown. Verify, does your answer ensure all constraints (if any) on the answer.
- Guessing when nothing works.
- Brute force the ans. Observer the patterns. Based on them, make assumptions and start simplifying the equations.
- When multiple variables start putting in values, simple ones like 0,1,2.
- Two values, maybe use 1 and floor(y/x).
- Highest multiple of x≤y is simply int(y/x)*x and y-floor(y/x) is simply y%x.
Binary search
- maximize the minimum