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 matrixMultiplication (matrixA, matrixB) { | |
const matrixC = matrixA.map(x => matrixB[0].map(y => 0)); | |
const lengthR = matrixA.length | |
const lengthC = matrixA[0].length | |
const lengthB = matrixB[0].length | |
let k = 0 | |
for (let i = 0; i < lengthR; i++) { | |
k = 0 | |
for (let j = 0; j < lengthB; j++) { | |
if(matrixA[i][j] === undefined || matrixB[j][k] === undefined) |
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
var maxArea = function(height) { | |
let pointer1, pointer2; | |
let sum = 0; | |
let length = height.length | |
let calculate = (pointer1, pointer2) => { | |
if(height[pointer1] === 0 || height[pointer2] === 0) | |
return 0 | |
return Math.min(height[pointer1], height[pointer2]) * Math.abs(pointer2 - pointer1) || 1; | |
} | |
const end = length - 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
var groupAnagrams = function(array) { | |
const result = array.reduce((acc, cur, index) => { | |
let word = cur.split(``).sort((a, b) => a.localeCompare(b)).join(``) | |
if(!acc[word]){ | |
acc[word] = [] | |
acc[word].push(array[index]) | |
} else { | |
acc[word].push(array[index]) | |
} | |
return acc |
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 filterValidLands(allPositions, landPositions){ | |
return allPositions.length - landPositions.length; | |
} | |
function dfs(matrix, matrixR, matrixC, currentMove, visitedNodes, landPositions) { | |
const [x, y] = currentMove.shift(); | |
const possibleMoves = [[x - 1, y], | |
[x, y -1], | |
[x + 1, y], | |
[x, y + 1]]; |