-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug in hint and add explanations #36
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I just have a couple suggestions that to me helps the clarity.
* `return k` | ||
1. Set `index` to `0` | ||
1. `while index < len(arr) - 1` | ||
2. `k = k - arr[0] - 1` | ||
* `k` will be decremented to represent the number of remaining missing nums. This line accounts for missing nums before `arr[0]`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest calling out where the 1 is coming from.
* `k` will be decremented to represent the number of remaining missing nums. This line accounts for missing nums before `arr[0]`. | |
* `k` will be decremented to represent the number of remaining missing nums. This line accounts for missing nums before `arr[0]`, which we expect to start from 1, the smallest positive integer. |
* `current_missing = arr[index + 1] - arr[index] - 1` | ||
* `if k <= current_missing` | ||
* `current_missing` represents how many missing numbers between `arr[index + 1]` and `arr[index]` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest accounting for where the 1 is coming from.
* `current_missing` represents how many missing numbers between `arr[index + 1]` and `arr[index]` | |
* `current_missing` represents how many missing numbers there are between `arr[index + 1]` and `arr[index]`, which should differ by only 1 if there are no missing numbers. |
* `if k <= current_missing` | ||
* `current_missing` represents how many missing numbers between `arr[index + 1]` and `arr[index]` | ||
* `if k <= current_missing:` | ||
* We found the original kth missing number. The value is `arr[index] + k`. We return it and exit the loop. | ||
* `return arr[index] + k` | ||
* `k = k - current_missing` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We mention that k gets decremented above, but I think noting why again here is helpful.
* `k = k - current_missing` | |
* `k = k - current_missing` | |
* Reduce the number of missing numbers we are looking for by the number of missing numbers we just found. |
Resulting function that passes all tests: