FIRST BAD VERSION | LEETCODE 278 | PYTHON BINARY SEARCH SOLUTION
Vložit
- čas přidán 24. 07. 2024
- Channel Discord Community: / discord
Problem Link: leetcode.com/problems/first-b...
Today we are solving a question that is fantastic for learning Binary Search. it's First Bad Version (Leetcode 278). This question is great because it's very easy intuition wise and it exposes us to a different variation of binary search where we want to move our pointers and ultimately return one of them instead of returning from inside the binary search.
TIMESTAMPS
00:00 Intro
00:08 Question Prompt
00:40 Basic Example
01:40 Solution Intuition
03:31 Coding
07:05 Time/Space Complexity
07:35 Outro - Věda a technologie
Thanks nice explanation, but on leetcode your code fails for this test case... when Input: n = 1, bad = 1
Output: 1. Can you please advise how to handle this edge case?
You must have copied the code wrong. My solution is still accepted there
Thanks❤
Why are you starting from 0 but ending with n instead of n-1? No list/array element starts from 1 and ends with n. It starts from 0 and ends with (n-1). So why have you done that? Importantly, if you did not know you had to do that, how would you know! other than memorizing?
You are not working with arrays here so if you only go to n -1 you will miss the last element in the case it is the last one in the list.
yes but we're starting from 0 not 1, so how will i miss (n-1)? The more important question is : if you didn't ***Remember** to do this 0 to n, how would you know that you have to do this? And if you are going to n, why not from 1, why are you starting from 0?
@@adityahpatelYou should actually start it at 1. I probably wrote 0 because I've done so many binary search questions and it's just muscle memory at this point.
Should just start at 1 even though 0 also works here but 1 is better actually.
basically write git bisect 😅