Open darwinrlo opened 4 years ago
Practice session with Adil
Morning session on Pramp
pgbovine:
When the interviewer presents a question to you, immediately sketch out a bunch of examples and ask a ton of clarifying questions to make sure you understand exactly what the interviewer is asking you to do.
Draw several examples and ask your interviewer questions of the form, "for this case, you want the result to be X, right?" Do not make any assumptions without first checking them over with your interviewer.
LeetCode: Maximal Rectangle Geeks for Geeks: Maximum sum rectangle in a 2D matrix
Other
LeetCode: Maximum Sum Subarray
Session with Anthony on Pramp LeetCode: Decode Ways
At minimum, implement the naive solution and just explain the optimal solution. Come up with and articulate the naive (brute-force) solution. If nothing comes to mind, just start coding up the naive solution; at minimum, a working deliverable must be delivered. Proper edge case handling can be sacrificed if necessary though base cases for recursive algorithms are more important than other kinds of edge cases.
Afterward, if the optimal solution has occurred to me, explain what it would be and give its time and space complexity. Give the sense that it would be a waste of time for me to actually code it up. Depending on the interviewers' impression of me, I may be able to skip coding it up.
Facebook literally just wants you to chug out solutions to two LeetCode Mediums, edge cases be damned. For the first problem, try to move past the edge cases. Really internalizing the patterns from Grokking the Coding Interview will help a lot here... I can do this over the weekend.
To pop from the left of a deque, use popleft. pop pops from the right side of the deque.
Facebook Similar: LeetCode: Spiral Matrix
Don't do:
output = [[None]*C]*r
Instead, do:
output = [[None] for _ in range(C)] for _ in range(R)]
To add to the right of the queue, use append (not appendright). To add to the left side, use appendleft.
To remove an element from the right side of the queue, use pop. Use popleft to remove an element from the left side of the queue.
Use BFS to find the shortest path as opposed to DFS.
5/8/2020
Similar Problem: LeetCode: 4Sum
Observations & Insights
What Went Well
Missteps
I didn't crystallize enough of the brute-force solution to assess its time complexity. I only went through the motions of sketching out the the brute-force solution. Then I attempted to use dynamic programming, which was unnecessary and/or would've been a dead end.
I incremented a dictionary instead of a dictionary entry. Next time, make sure I have properly indexed a dictionary.
My initial thought was to create a hash table that maps numbers to their indices. It turns out this was overkill. Since I don't need to provide indices in the solution, I just need to know if there are enough occurrences in the array to cover the number of occurrences in the quadruplet under inspection. This means it is sufficient to map numbers to their counts.
There was a bug in my program. I got the subtraction backward -- substantially due to my chosen capitalization. s was the function parameter and S was my variable, so I did S - s when the correct expression was s - S. Going forward, make sure I am subtracting the numbers in the right order. Be aware that I may be misled by the capitalization of the variable names.
Learnings and Opportunities for Improvement
Possible Next Steps
My Advice for My Practice Partner
Appendix: defaultdict
Don't do:
Do:
Appendix: enumerate
To pair each element of an iterable with its index, use enumerate, which returns an iterator that gives the next element in a tuple with its index. (To get the next element of an iterator, use next().)