Skip to content

Instantly share code, notes, and snippets.

View spiterman's full-sized avatar
🏠
Working from home

Sergey Piterman spiterman

🏠
Working from home
View GitHub Profile
function addNode(graph, nodeToAdd) {
if(graph[nodeToAdd] === undefined) {
graph[nodeToAdd] = new Set()
}
return graph
}
function addConnection(graph, origin, destination) {
addNode(graph, origin)
function PowerSet(str) {
let result = []
function constructSubSet(subSet, index) {
if(index >= str.length) {
result.push(subSet)
return
}
constructSubSet(subSet, index + 1)
constructSubSet(subSet + str[index], index + 1)
let nthFib = (n) => n <= 1 ? 1 : nthFib(n - 1) + nthFib(n - 2);
function nThFibonacciTable(n) {
let table = [1, 1]
for (let i = 2; i <= n; i++) {
let nextFib = table[i - 1] + table[i - 2]
table.push(nextFib)
}
return table[n]
}
function nThFibonacci(n) {
if(n <= 1) return 1
return nThFibonacci(n - 1) + nThFibonacci(n - 2)
}
// Linear Space
function houseRobber1(houses) {
let max_gold = []
for(let i = 0; i < houses.length; i++) {
let current = houses[i];
let prevMax = max_gold[i - 1] || 0;
let twoBackMax = max_gold[i - 2] || 0;
max_gold.push(Math.max(current + twoBackMax, prevMax));
let counter = 0;
function houseRobberRecursive(arr) {
function stealFromHouse(index) {
if(index >= arr.length) {
counter++;
return 0;
}
return Math.max(arr[index] + stealFromHouse(index + 2), stealFromHouse(index + 1));
}
function houseRobberRecursive(arr) {
function stealFromHouse(index) {
if(index >= arr.length) {
return 0;
}
return Math.max(arr[index] + stealFromHouse(index + 2), stealFromHouse(index + 1));
}
return stealFromHouse(0);
}
@spiterman
spiterman / MergeKSortedArrays.js
Created November 27, 2018 05:29
How to Merge K Sorted Arrays Efficiently
// Space: O(NK) (Plus O(K) for the heap)
// Time: O(NK log(K))
function mergeKSorted(arrays) {
let result = [];
let minHeap = [];
arrays.forEach((array, index) => {
minHeap.push({
@spiterman
spiterman / hackathon_how_to.md
Created November 12, 2018 20:36 — forked from sergmetelin/hackathon_how_to.md
Hackathon Getting Started guide

About EOSIO

The EOS.IO software introduces a new blockchain architecture designed to enable vertical and horizontal scaling of decentralized applications. This is achieved by creating an operating system-like construct upon which applications can be built. The software provides accounts, authentication, databases, asynchronous communication and the scheduling of applications across many CPU cores or clusters. The resulting technology is a blockchain architecture that may ultimately scale to millions of transactions per second, eliminates user fees, and allows for quick and easy deployment and maintenance of decentralized applications, in the context of a governed blockchain.

About this guide:

Full documentation can be found at https://developers.eos.io/

This means your portal is correctly setup for the hackathon.