How to Approach problem ??

  1.  Firstly, read the question carefully. 
    • If able to understand 100% => don't read the test case
    • else read the test cases to get the feel
  2. If not able to come up with any approach --> think of brute force -> then optimize
  3. Categorize the problem where it lies
    • Brute Force
    • Maths
    • Binary Search 
    • Greedy
    • DP
    • Graph
    • Bitwise stuffs

  4. If given tree --> Visualize as shown in image (Think of BFS/DFS)
  5. If given subarray -> can think of prefix sum or dp

  6. If the code seems too lengthy => simplify => There must be a way
    • Can use MATHS sometimes to simplify the expression or logic

  7. If dp => lookout for the transition and state definition first
  8. Whenever including edge case in anywhere always be 100% sure (even though you think its correct, it may be wrong).
  9. Lookout for edge cases !!!
    • If sure of solution => spend time on edge cases, even it seems trivial

  10. If stuck 
    • Check for negation of problem demand
    • what will happen if include one by one 
    • solve for small values
    • look for trend and the overlapping portions (if TLE)

  11. Try to simplify problem statement (if feels complex)
  12. If remove subarray -> can use prefix + suffix array combination
  13. If hard to find for equality --> find for inequality and adjust
    • Example - Find no. of subarray whose product = k → let's say it's easy to find no. of subarray whose product ≤ k → ans = fun(k) - fun(k-1)

Comments

Popular posts from this blog

Templates (for CP)

DSA Trees + Heap

Modular Basics + Number Theory + Permutations