From 2ec4f9dc887a465850170b1ebb36f95ac12eeb28 Mon Sep 17 00:00:00 2001 From: Jerica Huang Date: Wed, 18 May 2022 20:24:41 -0700 Subject: [PATCH 1/5] typo correction --- 08/kth-missing-positive-number.checkpoint.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/08/kth-missing-positive-number.checkpoint.md b/08/kth-missing-positive-number.checkpoint.md index c689582..4275316 100644 --- a/08/kth-missing-positive-number.checkpoint.md +++ b/08/kth-missing-positive-number.checkpoint.md @@ -108,7 +108,7 @@ Implement `kth_missing_positive_number`. Use these tests to guide your solution ```python def kth_missing_positive_number(numbers, k): ''' - INPUT: List of numbers in increating order & a positive integer k + INPUT: List of numbers in increasing order & a positive integer k OUTPUT: The kth missing number ''' From dcd6d4b24437bc37a223fc145c2d7c98239321c0 Mon Sep 17 00:00:00 2001 From: Jerica Huang Date: Wed, 18 May 2022 21:10:39 -0700 Subject: [PATCH 2/5] fix bugs in the hint, add additional explanations. --- 08/kth-missing-positive-number.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/08/kth-missing-positive-number.md b/08/kth-missing-positive-number.md index 79d4cd2..f964c85 100644 --- a/08/kth-missing-positive-number.md +++ b/08/kth-missing-positive-number.md @@ -209,12 +209,17 @@ Example Steps for an O(n) solution: 1. if `k < arr[0]` * `return k` 1. Set `index` to `0` -1. `while index < len(arr) - 1` - * `current_missing = arr[index + 1] - arr[index] - 1` - * `if k <= current_missing` +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]`. +4. `while index < len(arr) - 1` + * `current_missing = arr[index + 1] - arr[index] - 1` if `index`>0` + * `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` -1. return the last element of the list plus the remaining value of `k`. + * `index = index + 1` +5. return the last element of the list plus the remaining value of `k`. ### !end-explanation From 2d5467a13e8243c364f40c6a3d041bb1c49aa5af Mon Sep 17 00:00:00 2001 From: Jerica Huang Date: Wed, 18 May 2022 21:11:30 -0700 Subject: [PATCH 3/5] missing ` --- 08/kth-missing-positive-number.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/08/kth-missing-positive-number.md b/08/kth-missing-positive-number.md index f964c85..516ecbf 100644 --- a/08/kth-missing-positive-number.md +++ b/08/kth-missing-positive-number.md @@ -210,9 +210,9 @@ Example Steps for an O(n) solution: * `return k` 1. Set `index` to `0` 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]`. + * `k` will be decremented to represent the number of remaining missing nums. This line accounts for missing nums before `arr[0]`. 4. `while index < len(arr) - 1` - * `current_missing = arr[index + 1] - arr[index] - 1` if `index`>0` + * `current_missing = arr[index + 1] - arr[index] - 1` * `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. From e50566a566ab5e164851b4e7061d94857fd76177 Mon Sep 17 00:00:00 2001 From: Jerica Huang Date: Wed, 18 May 2022 21:12:18 -0700 Subject: [PATCH 4/5] formatting --- 08/kth-missing-positive-number.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/08/kth-missing-positive-number.md b/08/kth-missing-positive-number.md index 516ecbf..8979aae 100644 --- a/08/kth-missing-positive-number.md +++ b/08/kth-missing-positive-number.md @@ -206,15 +206,15 @@ Write the logical steps here. Example Steps for an O(n) solution: 1. Check for valid input -1. if `k < arr[0]` +1. if `k < arr[0]:` * `return k` 1. Set `index` to `0` -2. `k = k - arr[0] - 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]`. -4. `while index < len(arr) - 1` +4. `while index < len(arr) - 1:` * `current_missing = arr[index + 1] - arr[index] - 1` * `current_missing` represents how many missing numbers between `arr[index + 1]` and `arr[index]` - * `if k <= current_missing + * `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` From f4f0f2ed0713e19c61c3ca483a8bdf7921781c70 Mon Sep 17 00:00:00 2001 From: Jerica Huang Date: Wed, 18 May 2022 21:23:44 -0700 Subject: [PATCH 5/5] typo correction --- 08/kth-missing-positive-number.checkpoint.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/08/kth-missing-positive-number.checkpoint.md b/08/kth-missing-positive-number.checkpoint.md index 75127cb..1784815 100644 --- a/08/kth-missing-positive-number.checkpoint.md +++ b/08/kth-missing-positive-number.checkpoint.md @@ -108,7 +108,7 @@ Implement `kth_missing_positive_number`. Use these tests to guide your solution ```python def kth_missing_positive_number(numbers, k): ''' - INPUT: List of positive numbers in increating order & a positive integer k + INPUT: List of positive integers in increasing order & a positive integer k OUTPUT: The kth missing number '''