Skip to content

Instantly share code, notes, and snippets.

View cazlu8's full-sized avatar
🎯
Focusing

Lucas Reichert Siqueira cazlu8

🎯
Focusing
  • Florianópolis, SC.
View GitHub Profile
@cazlu8
cazlu8 / gist:b695cd3cad7af8c8de7dbb87412d168f
Created July 26, 2022 00:34
sparse matrix multiplication
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)
@cazlu8
cazlu8 / gist:84ed80824c7088740c7e44bffd9fe4ec
Created July 24, 2022 00:35
Container With Most Water
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;
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
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]];