Strategies to leetcode problems

Goldman Sachs xTy
Mar 14 15 Comments

Hey guys, I usually face difficulties when approaching completely new problem and get stuck eventually.

For eg.

https://leetcode.com/problems/maximal-rectangle/description/

My thought process looking at this problem:

- hmm dfs?
- but how do I track equal bounds on opposite side?
- maybe dfs does not work after all..
- oh maybe first store all locations of “1” in a hashmap with index. In next iteration, start from valid “1” location then check 4 directions with continuous “1” until we encounter “0”. Distance would be relative from starting position.
- hmm but how do I keep track of equal bounds..

After some time I literally freeze and give up.
How do you run algorithms in your mind efficiently?

I have good grasp on all popular algorithms, but I have issues in correctly choosing and applying them on a never seen problem.

What does your thought process look like when you see this kind of problem?

I have facebook onsite coming up in 2 weeks. Please help. :)

comments

Want to comment? LOG IN or SIGN UP
TOP 15 Comments
  • Cadence tigerk
    read the answer and memorize it. try to reduce the number of the "never seen questions" is the most efficient way for the interview.
    Mar 146
    • Qualcomm dynasty001
      This actually works. I have started keeping notes using “anki” as well.
      Mar 14
    • New Leetup
      I strongly disagree with this strategy. Memorization does not scale one you do 500+ questions. Focus on improving your problem solving skills not memorizing.
      Mar 14
    • Qualcomm dynasty001
      I think he doesnt mean “memorization” per se. Its like when yiu do one thing so many times , it just gets imprinted in your memory. This is basically learning a pattern. Same reason people use “spaced repeatition” to remember things.
      Mar 14
    • New Leetup
      Dude read his post he just says “read the answer and memorize it”. That’s not solving the question, you don’t get better that way. It is however the most effective way to study if you’re short on time. Still doesn’t scale.
      Mar 14
    • Qualcomm dynasty001
      Yeah i gave him the benefit of doubt that he really didnt mean “memorize it” . How d fck can one memorize 200+ LC questions lol
      Mar 14
    • Sapient / Eng
      geek007

      SapientEng

      PRE
      JPMorgan Chase
      geek007more
      @dynasty001 it's true. interviews are not der to solve the problem they are to check your coding speed. only memorization work. They asked me Hard on the phone and gave 30 mins to solve.
      Mar 21
  • Goldman Sachs abcdeaa
    You should know largest histogram in an array to solve this one
    Mar 140
  • Amazon jessica22
    ^This. (And then you take their site down when the problem is outside of your “knowledge”)
    Mar 140
  • Google / Eng
    LeeJaeDong

    GoogleEng

    PRE
    Amazon
    LeeJaeDongmore
    I solved this question at an onsite by reducing it to the “largest rectangle in a histogram” problem.
    Mar 143
    • Salesforce exitways
      So if you didn’t know largest rectangle in histogram problem, do you think you would have still solved it? Thanks!

      P.s. is your nickname reference to Zerg SC player?
      Mar 14
    • Facebook Probe
      It is Jaedong himself.
      Mar 14
    • Google / Eng
      LeeJaeDong

      GoogleEng

      PRE
      Amazon
      LeeJaeDongmore
      Lol I don’t have his apm! If I didn’t know the histogram problem, would’ve failed for sure. Especially since it was a follow up question in the last 20 minutes after I solved the first 2 different questions.
      Mar 14
  • Citrix Systems peda
    I think for Facebook you need to memorize and practice a lot. And lot depends on luck. I honestly feel they’re are very few intelligent ppl who can solve any problem at any time rest all are mug heads and also depends on luck !! Those very few intelligent ppl will be working for confidential projects at MSR or something better
    Mar 140
  • Synchrony ————
    I have similar issues. I think it's all about practice and intuition. I also want to hear what others have to say.
    Mar 140

Join verified employees in our anonymous social network!Download the app!

close