Last active
November 29, 2021 05:42
-
-
Save wxgrzr/6deb39b4bde1c6078321a0ffba0e6da5 to your computer and use it in GitHub Desktop.
Revisions
-
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 8 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ # Find Maximum in Sliding Window [Link](https://www.educative.io/module/lesson/data-structures-in-javascript/gxnlB9N5MR9) @@ -7,20 +6,20 @@ ## Description Given a large array of integers and a window size of `w` find the current maximum value in the window as the window slides through the entire array. Let's try to find all maximums for `w = 3`: [-4, 2, -5, 3, 6] **Step 1:** for the first *3* elements, max is 2. [-4, 2, -5], 3, 6 * **Step 2:** Slide `window` one position to right and the max is now *3* -4, [2, -5, 3], 6 * **Step 3:** In the last `window` the max is 6. @@ -71,7 +70,7 @@ console.log("Array = " + array); console.log("Max = " + ffindMaxSlidingWindow(array, 3)); // Max = 3,4,5,6,7,8,9,10 let array1 = [10, 6, 9, -3, 23, -1, 34, 56, 67, -1, -4, -8, -2, 9, 10, 34, 67] console.log("Array = " + array1); console.log("Max = " + ffindMaxSlidingWindow(array1, 3)) // Max = 10,9,23,23,34,56,67,67,67,-1,-2,9,10,34,67 @@ -88,4 +87,3 @@ The runtime complexity in *`linear, O(n)`*. Memory complexity is *`linear, O*(w)`*, where `w` is the window size -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,5 +3,5 @@ Educative Modules [[1-SlidingWindow]] [[DSAX-Modules/educative.io/2-RotatedArray]] -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Rotated Array Search [[0-Index]] ## Description -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Rotated Array Search [[0-Index]] ## Description -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -204,4 +204,4 @@ This solution works iteratively so te algo comes down to **`O(1)`** even though --- Next - [[3-SmallestCommonNumber.md]] -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -204,4 +204,4 @@ This solution works iteratively so te algo comes down to **`O(1)`** even though --- Next - [[3-]] -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -204,4 +204,4 @@ This solution works iteratively so te algo comes down to **`O(1)`** even though --- Next - [[]] -
wxgrzr revised this gist
Nov 29, 2021 . No changes.There are no files selected for viewing
-
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -202,6 +202,6 @@ console.log("Key(6) found at: " + binarySearchRotated(v2, 6)); ``` This solution works iteratively so te algo comes down to **`O(1)`** even though the logic remains the same --- Next - [] -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -202,4 +202,6 @@ console.log("Key(6) found at: " + binarySearchRotated(v2, 6)); ``` This solution works iteratively so te algo comes down to **`O(1)`** even though the logic remains the same -- Next - -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -202,3 +202,4 @@ console.log("Key(6) found at: " + binarySearchRotated(v2, 6)); ``` This solution works iteratively so te algo comes down to **`O(1)`** even though the logic remains the same Next - -
wxgrzr revised this gist
Nov 29, 2021 . No changes.There are no files selected for viewing
-
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -202,4 +202,3 @@ console.log("Key(6) found at: " + binarySearchRotated(v2, 6)); ``` This solution works iteratively so te algo comes down to **`O(1)`** even though the logic remains the same -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -200,4 +200,6 @@ let v2 = [4, 5, 6, 1, 2, 3]; console.log("Key(3) found at: " + binarySearchRotated(v2, 3)); console.log("Key(6) found at: " + binarySearchRotated(v2, 6)); ``` This solution works iteratively so te algo comes down to **`O(1)`** even though the logic remains the same -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -200,4 +200,4 @@ let v2 = [4, 5, 6, 1, 2, 3]; console.log("Key(3) found at: " + binarySearchRotated(v2, 3)); console.log("Key(6) found at: " + binarySearchRotated(v2, 6)); ``` This solution works iteratively so te algo comes down to **`O(1)`** -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -200,4 +200,4 @@ let v2 = [4, 5, 6, 1, 2, 3]; console.log("Key(3) found at: " + binarySearchRotated(v2, 3)); console.log("Key(6) found at: " + binarySearchRotated(v2, 6)); ``` This solution works iteratively so te algo comes down to **``** -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -200,4 +200,4 @@ let v2 = [4, 5, 6, 1, 2, 3]; console.log("Key(3) found at: " + binarySearchRotated(v2, 3)); console.log("Key(6) found at: " + binarySearchRotated(v2, 6)); ``` This solution works iteratively so te algo comes down to **`` -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -200,4 +200,4 @@ let v2 = [4, 5, 6, 1, 2, 3]; console.log("Key(3) found at: " + binarySearchRotated(v2, 3)); console.log("Key(6) found at: " + binarySearchRotated(v2, 6)); ``` This solution works iteratively so te algo comes down to `` -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -200,4 +200,4 @@ let v2 = [4, 5, 6, 1, 2, 3]; console.log("Key(3) found at: " + binarySearchRotated(v2, 3)); console.log("Key(6) found at: " + binarySearchRotated(v2, 6)); ``` This solution works iteratively so te algo comes down to -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -200,4 +200,4 @@ let v2 = [4, 5, 6, 1, 2, 3]; console.log("Key(3) found at: " + binarySearchRotated(v2, 3)); console.log("Key(6) found at: " + binarySearchRotated(v2, 6)); ``` This solution works iteratively so te al -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -200,4 +200,4 @@ let v2 = [4, 5, 6, 1, 2, 3]; console.log("Key(3) found at: " + binarySearchRotated(v2, 3)); console.log("Key(6) found at: " + binarySearchRotated(v2, 6)); ``` This solution works iteratively so te -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -200,4 +200,4 @@ let v2 = [4, 5, 6, 1, 2, 3]; console.log("Key(3) found at: " + binarySearchRotated(v2, 3)); console.log("Key(6) found at: " + binarySearchRotated(v2, 6)); ``` This solution works iteratively -
wxgrzr revised this gist
Nov 29, 2021 . No changes.There are no files selected for viewing
-
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -150,7 +150,7 @@ The memory complexity of this solution is constant `O(1)`. ```javascript let binarySearchRotated = function(arr, key) { start = 0; @@ -198,6 +198,6 @@ console.log("Key(6) found at: " + binarySearchRotated(v1, 6)); let v2 = [4, 5, 6, 1, 2, 3]; console.log("Key(3) found at: " + binarySearchRotated(v2, 3)); console.log("Key(6) found at: " + binarySearchRotated(v2, 6)); ``` -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 49 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -150,5 +150,54 @@ The memory complexity of this solution is constant `O(1)`. ``` let binarySearchRotated = function(arr, key) { start = 0; end = arr.length - 1; if (start > end){ return -1; } while (start <= end){ mid = start + Math.floor((end - start) / 2); if (arr[mid] == key){ return mid; } if (arr[start] <= arr[mid] && key <= arr[mid] && key >= arr[start]){ end = mid - 1; } else if (arr[mid] <= arr[end] && key >= arr[mid] && key <= arr[end]){ start = mid + 1; } else if (arr[end] <= arr[mid]){ start = mid + 1; } else if (arr[start] >= arr[mid]){ end = mid - 1; } else{ return -1; } } return -1; }; let v1 = [6, 7, 1, 2, 3, 4, 5]; console.log("Key(3) found at: " + binarySearchRotated(v1, 3)); console.log("Key(6) found at: " + binarySearchRotated(v1, 6)); let v2 = [4, 5, 6, 1, 2, 3]; console.log("Key(3) found at: " + binarySearchRotated(v2, 3)); console.log("Key(6) found at: " + binarySearchRotated(v2, 6)); ``` -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -150,3 +150,5 @@ The memory complexity of this solution is constant `O(1)`. -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -146,6 +146,7 @@ The runtime complexity of this solution is logarithmic `O(log n)`. ### Memory complexity The memory complexity of this solution is constant `O(1)`. -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -146,6 +146,6 @@ The runtime complexity of this solution is logarithmic `O(log n)`. ### Memory complexity The memory complexity of this solution is constant, `O(1)`. -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -146,6 +146,6 @@ The runtime complexity of this solution is logarithmic `O(log n)`. ### Memory complexity The memory complexity of this solution is constant, O(1)O(1)`. -
wxgrzr revised this gist
Nov 29, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -143,7 +143,7 @@ Solution 2: Iterative ### Runtime complexity The runtime complexity of this solution is logarithmic `O(log n)`. ### Memory complexity The memory complexity of this solution is constant, O(1)O(1).
NewerOlder