Skip to content

Instantly share code, notes, and snippets.

View syphh's full-sized avatar

Syphax Ait oubelli syphh

View GitHub Profile
class Node:
def __init__(self, val=0, neighbors=None):
self.val = val
self.neighbors = neighbors if neighbors is not None else []
def dfs(node, node_map):
clone = Node(node.val)
node_map[node.val] = clone
for neighbor in node.neighbors:
function isLowerTriangular(mat){
let matSize = mat.length;
for(let i = 0; i < matSize; i++){
for(let j = i+1; j < matSize; j++){
if(mat[i][j] != 0)
return false;
}
}
return true;
}
@syphh
syphh / addTimer.js
Created December 22, 2019 21:48
Adding timer
function foo(){
console.time();
// function code
console.timeEnd();
}
@syphh
syphh / randMat.js
Created December 22, 2019 21:44
100*100 random matrix
let randomMat = [...new Array(100)].map(row => [...new Array(100)].map(cell => Math.floor(Math.random() * 10)));
@syphh
syphh / sumSubDynamic.js
Created December 22, 2019 21:24
Sum of sub-matrices (dynamic programming method)
function dynamicSumSubmatrices(mat){
// n and m represent dimensions of the matrix
let n = mat.length;
let m = mat[0].length;
// declaring a (n*m) matrix
let sumMat = [...new Array(n)].map(row => [...new Array(m)]);
// part 1
sumMat[0][0] = mat[0][0];
@syphh
syphh / sumSubBruteForce.js
Last active December 22, 2019 21:44
Sum of sub-matrices (Brute force method)
function sumSubmatrices(mat){
// n and m represent dimensions of the matrix
let n = mat.length;
let m = mat[0].length;
// declaring a (n*m) matrix
let sumMat = [...new Array(n)].map(row => [...new Array(m)]);
for(let i = 0; i < n; i++){
for(let j = 0; j < m; j++){