Join Ex-Google and Ex-Facebook software engineers TechLead and Joma with our daily interview programming problems.
Here's how it works:
|This can be done recursively and iteratively. See if you can get both solutions.|
This problem can be solved recursively or iteratively. We traverse the two linked lists in parallel, advancing both pointers simultaneously. If the first list's value is smaller we advance that one, otherwise we advance the second list. If either list is shorter, then we take values from the longer list.
The time complexity is linear O(n) since both lists are traversed just once. The space complexity of the recursive algorithm is linear O(n), since it builds up a recursive stack that may be as deep as the length of both lists. The space complexity of the iterative solution is constant O(1), since only a few variables are used.
Daily, consistent practice is the best way to get good at solving interview programming questions. In this field, it is a lifelong skill whether you are a beginner or senior software engineer.
There's no catch! Just sign up and we'll start sending you free interview coding problems.
Have a great day!
TechLead and Joma
"TechLead" is Patrick Shyu - ex-Google tech lead, ex-Facebook Staff Software Engineer, multi-millionaire app entrepreneur, digital nomad, and software engineer. He has conducted over 100 interviews at Google.
"Joma" is Jonathan Ma - he has done internships and full-time at Citadel, Linkedin, Facebook and Microsoft. He has worked as a data scientist, software engineer and PM. He is currently working as a software engineer in FANG.
Where should we send these?