This file contains 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
let arr = [1,2,3,4,5]; | |
console.log(arr.slice(1, -3)); // [2] | |
console.log(arr); // [1,2,3,4,5] | |
// Similarly, with -2 | |
let arr = [1,2,3,4,5]; | |
console.log(arr.slice(1, -2)); // [2,3] | |
console.log(arr); // [1,2,3,4,5] |
This file contains 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
let arr = [1,2,3,4,5]; | |
console.log(arr.slice(1, 3)); // [2,3] | |
console.log(arr); // [1,2,3,4,5] |
This file contains 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
let arr = [1,2,3,4,5]; | |
console.log(arr.slice(1)); // [2,3,4,5] | |
console.log(arr); // [1,2,3,4,5] |
This file contains 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
let arr = [1,2,3,4,5]; | |
// two items starting from index 1 would be removed and 3 new items would be added | |
console.log(arr.splice(1, 2, 6, 7, 8)); // [2,3] | |
console.log(arr); // [1,6,7,8,4,5] |
This file contains 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
let arr = [1,2,3,4,5]; | |
console.log(arr.splice(1, 2)); // [2,3] - two items starting from index 1 would be removed | |
console.log(arr); // [1,4,5] |
This file contains 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
let arr = [1,2,3,4,5]; | |
console.log(arr.splice(1)); // [2,3,4,5] | |
console.log(arr); // [1] |
This file contains 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
static void minimumBribes(int[] a) { | |
int n = a.length; | |
int sum = 0; | |
for(int i = n-1; i >=0; i--) { | |
if ((a[i] - (i+1)) > 2) { | |
System.out.println("Too chaotic"); | |
return; | |
} | |
This file contains 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
/** | |
* @param {number[][]} mat | |
* @param {number} k | |
* @return {number[]} | |
*/ | |
var kWeakestRows = function(mat, k) { | |
const n = mat.length; | |
let outArr = []; | |
for(let i=0; i<n; i++) { | |
outArr.push({count: 0, index: i}) |
This file contains 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
/** | |
* @param {number[][]} mat | |
* @param {number} k | |
* @return {number[]} | |
*/ | |
var kWeakestRows = function(mat, k) { | |
const n = mat.length; | |
let outArr = []; | |
for(let i=0; i<n; i++) { | |
outArr.push({count: 0, index: i}) |
This file contains 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
public int calculateArea(int a[], int n) { | |
Stack<Integer> s = new Stack<Integer>(); | |
int maxArea = 0; | |
int tp; | |
int area; | |
int i=0; | |
while(i < n) { | |
if(s.empty() || a[s.peek()] <= a[i]) { |
NewerOlder