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
| /** | |
| given two non-empty arrays A and B consisting of N integers, returns the number of fish that will stay alive. | |
| For example, given the arrays shown above, the function should return 2, as explained above. | |
| Write an efficient algorithm for the following assumptions: | |
| N is an integer within the range [1..100,000]; | |
| each element of array A is an integer within the range [0..1,000,000,000]; | |
| each element of array B is an integer that can have one of the following values: 0, 1; |
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
| function solution(A) { // [1,5,2,1,4,0] | |
| var starts = []; // disk start points | |
| var ends = []; // disk end points | |
| for (var i=0; i<A.length; i++) { | |
| starts.push(i - A[i]); // [-1, -4, 0, 2, 0, 5] | |
| ends.push(i + A[i]); // [1, 6, 4, 4, 8, 5] | |
| } | |
| starts.sort( (a,b) => a-b) // [ -4, -1, 0, 0, 2, 5 ] | |
| ends.sort( (a,b) => a-b) // [ 1, 4, 4, 5, 6, 8 ] |
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
| function solution(A) { | |
| if (A.length < 3) return 0; | |
| A = A.sort( (a,b) => a - b) | |
| for (var i=0; i< A.length -2; i++) { | |
| const [p, q, r] = A.slice(i, i+3) | |
| if ( (p + q) > r && (p+r) > q && (q+r) > p) | |
| return 1 | |
| } |
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
| function solution(A) { | |
| n = A.length; | |
| maxProduct = Number.MIN_SAFE_INTEGER | |
| A = A.sort( (a,b) => a-b) // <--- Important | |
| maxProduct = Math.max(maxProduct, A[0] * A[1] * A[n-1]); | |
| maxProduct = Math.max(maxProduct, A[n-3] * A[n-2] * A[n-1]); | |
| return maxProduct; | |
| } |
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
| /** | |
| given a non-empty array A consisting of N integers, returns the starting position of the slice with the minimal average. If there is more than one slice with a minimal average, you should return the smallest starting position of such a slice. | |
| For example, given array A such that: | |
| A[0] = 4 | |
| A[1] = 2 | |
| A[2] = 2 | |
| A[3] = 5 | |
| A[4] = 1 |
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
| /** | |
| given a non-empty array A consisting of N integers and integer X, returns the earliest time when the frog can jump to the other side of the river. | |
| If the frog is never able to jump to the other side of the river, the function should return −1. | |
| For example, given X = 5 and array A such that: | |
| [1, 3, 1, 4, 2, 3, 5, 4] | |
| the function should return 6, as explained above. |
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
| function solution(N) { | |
| const binString = N.toString(2); | |
| const matches = binString.replace(/[0]+$/, '').match(/0+/g); | |
| return (matches || []).reduce( (acc, cur) => Math.max(acc, cur.length), 0); | |
| } |
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
| name: Release | |
| "on": | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| release: | |
| name: release | |
| runs-on: ubuntu-latest |
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
| $('#my-input').addEventListener('keydown', restrictKeyboardInput); | |
| $('#my-input').addEventListener('paste', restrictKeyboardInput); | |
| function restrictKeyboardInput(event) { | |
| if (event.type === 'keydown' && !event.key.match(/^[a-zA-Z0-9-_\ .]$/)) { | |
| if (event.keyCode === 8 || event.keyCode === 46 || event.keyCode === 9) { | |
| // Allow backspace, delete and Tab key | |
| } else if (event.keyCode >= 37 && event.keyCode <= 40) { | |
| // Allow left, right, up and down arrows | |
| } else { |
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
| angular.module('lazyLoading',[]) | |
| .component('childAngularComponent', ChildAngularComponent) | |
| .component('childChildAngularComponent', ChildChildAngularComponent); | |
| var ChildAngularComponent = { | |
| template: ` | |
| <div> | |
| <h2>I'm Child Angular Component</h2> | |
| <p>form.value: {{$ctrl.form.value}}</p> |