Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am brugnara on github.
  • I am brugnara (https://keybase.io/brugnara) on keybase.
  • I have a public key ASCoJBlnKDqzCqhNkSlpPVBbQvuRel9O-oKGyYRC7MnoFQo

To claim this, I am signing this object:

type SnapshotArray struct {
hash map[int]map[int]int
snap int
}
func Constructor(length int) SnapshotArray {
array := SnapshotArray{
map[int]map[int]int{},
0,
@brugnara
brugnara / lowest-common-ancestor-of-deepest-leaves.go
Created December 12, 2020 09:40
[golang] Given a BT, let's found the ancestor for the deepest leave/s
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func lcaDeepestLeaves(root *TreeNode) *TreeNode {
levels := map[int][]*TreeNode{}
@brugnara
brugnara / validate-bst-with-pointers.go
Created December 12, 2020 06:39
Validate a BST using pointers with golang
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func loopBST(root *TreeNode) bool {
if root == nil {
@brugnara
brugnara / loop-bst.go
Created December 12, 2020 06:37
Loop a BST using channel in golang
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func printBST(root *TreeNode) {
chn := make(chan int)
@brugnara
brugnara / n-queens.go
Last active December 11, 2020 21:05
Place N Queens on a NxN chessboard, with Go!
func totalNQueens(n int) int {
if n == 1 {
return 1
}
board := make([][]bool, n)
for i:=0;i<n;i++ {
board[i] = make([]bool, n)
}
@brugnara
brugnara / client.js
Created March 22, 2018 08:10 — forked from alepez/client.js
nodejs file transfer with http post
var request = require('request');
var path = require('path');
var fs = require('fs');
var filename = process.argv[2];
var target = 'http://localhost:3000/upload/' + path.basename(filename);
var rs = fs.createReadStream(filename);
var ws = request.post(target);
@brugnara
brugnara / README.md
Created April 9, 2016 12:01 — forked from oscarrenalias/README.md
Docker service discovery with HAproxy, consul and registrator on Docker Machine and Docker Swarm
@brugnara
brugnara / child.js
Created January 4, 2015 12:21
fork vs spawn, nodejs
var i = 0;
setInterval(function() {
if (i++ % 2) {
console.log('I\'m the child!');
} else {
console.error('I\'m the child!');
}
}, 1500);