Fix bug in hint and add explanations#36
Closed
jericahuang wants to merge 6 commits intoAda-Developers-Academy:mainfrom
Closed
Fix bug in hint and add explanations#36jericahuang wants to merge 6 commits intoAda-Developers-Academy:mainfrom
jericahuang wants to merge 6 commits intoAda-Developers-Academy:mainfrom
Conversation
kelsey-steven-ada
approved these changes
May 19, 2022
Contributor
kelsey-steven-ada
left a comment
There was a problem hiding this comment.
Thanks for updating this!
anselrognlie
approved these changes
May 20, 2022
Contributor
anselrognlie
left a comment
There was a problem hiding this comment.
Looks good. I just have a couple suggestions that to me helps the clarity.
| 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]`. |
Contributor
There was a problem hiding this comment.
Suggest calling out where the 1 is coming from.
Suggested change
| * `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. |
| 4. `while index < len(arr) - 1:` | ||
| * `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]` |
Contributor
There was a problem hiding this comment.
Suggest accounting for where the 1 is coming from.
Suggested change
| * `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:` | ||
| * 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` |
Contributor
There was a problem hiding this comment.
We mention that k gets decremented above, but I think noting why again here is helpful.
Suggested change
| * `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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resulting function that passes all tests: