How to Solve '35 Search Insert Position' on LeetCode? - Javascript

preview_player
Показать описание
Do you need more help with coding?
════════════════════════════
════════════════════════════

How to Solve "Search Insert Position" on LeetCode?

Problem: #35 Search Insert Position
Difficulty: Easy
Language: Javascript

Strategy: For Loop
Time Complexity: O(n)
Space Complexity: O(1)

Pseudo Code:

1. Loop through nums array.
a. Create condition if current index value is greater than or equal to target.
i. if true, return i.
2. Return length of nums

Let's Connect 💯:
════════════════════════════
Рекомендации по теме
Комментарии
Автор

Hey man, just going back and reviewing old Leet COde problems and I realized this problem is supposed to be done with O (log n) time complexity but your solution is O(n) and still gets accepted? What's going on here? My initial thought was to do binary search with left, right, and mid pointers but I could not get it to work, which is why I found your video.

codingismyreligion
Автор

Well done. Way faster and easier than my solution!

bruce.lee.
Автор

I need more explanation about the space complexity. WHy is it constant? We aren't taking up any space because we didn't store any data in some variables?

codingismyreligion
welcome to shbcf.ru