Tech IndustryNov 22, 2023
Oracleiwantmore$

Confused…. remember some/special case leetcode solutions?

Everyone says dont remember solution of problem. But some problems ( even easy ones) have very specific solutions/algorithms. E.g. problem 88 in leetcode. (merge sorted array) Should such solutions be remembered? What do you folks suggest? #google #leetcode #faang #meta #amazon

Poll
17 Participants
Select only one answer
New
DBaddict Nov 22, 2023

Memorizing is absolutely useless (outside of the base algos / patterns). You have to be able to do it on the fly.

Yahoo survivur Nov 22, 2023

What do you have to remember in this?

Oracle iwantmore$ OP Nov 22, 2023

That you have to use 3 pointers… and starting from back ( decreasing) . If that point is missed, it cant be solved in O(m+n)

Yahoo survivur Nov 22, 2023

But that’s very obvious thing. Two arrays so 2 read pointers. And then one write index pointer is obvious. If you start from beginning then you may overwrite the first array unread values. That’s why write from end. Because then no chance of overwriting. I think the only tricky part in the question is to handle case when first array is finished early so you still need to copy second array elements to first array. And if second array is finished earlier, then we are done.