Improved an algorithm from O(n log n) to O(m + n)

Recently, I’ve started reviewing algorithm problems I did in the past in order to find better solutions.

First one

https://leetcode.com/problems/merge-sorted-array/submissions/1134212643/?envType=study-plan-v2&envId=top-interview-150

Today is this one.

Improve one

https://leetcode.com/problems/merge-sorted-array/submissions/1192977276/?envType=study-plan-v2&envId=top-interview-150

My algorithm was O(n log n) before, but it is O(m + n) for now. The trick is inserting elements from the last of arrays.

Feel free to reach out to me on LinkedIn, which you can find below. Looking forward to connecting!

https://www.linkedin.com/in/tomoharu-tsutsumi-56051a126/

--

--

Tomoharu Tsutsumi

Senior Software Engineer at two industry-leading startups ( Go | Ruby | TypeScript | JavaScript | Gin | Echo | Rails | React | Redux | Next)