Merge Two Sorted Arrays Javascript Algorithm | Problem 2

preview_player
Показать описание
We are going to write a Javascript program to:
Merge two sorted Arrays/Lists, and we will do it in O(n) complexity.
Рекомендации по теме
Комментарии
Автор

We want more algorithm like this so that I can prepare for frontend developer interview preparation

anirbansarkar
Автор

I liked the last part who is awesome 😁

ayushiconnects
Автор

Good video with a readable solution that is easy to follow. However, this solution is not O(n), it is actually O(n^2). shift() is O(n) and it is compounding against the O(n) of the while loop, making it O(n^2).

theBlackbriar
Автор

what about mergeTwoLists([1, 3, 4, 1], [1, 2, 3]) . This code is not working on leetcode

Mentalist
Автор

this code wont work because the while loop has no counter and next will always be the same, so you will end up in that loop, also shift method has 0(n^2) time complexity

techrelayhub
Автор

use pointer instead of shift. shift is bad

alexlui
Автор

Readable solution. Worst time and space complexity. Don't call it optimised please. Frankly speaking, this is the worst solution that can be written.
Each time you use shift(), it is being iterated through the array. O(n^2) is the complexity while adding two arrays and sorting has a O(n).

narenmids