Skip to content

Instantly share code, notes, and snippets.

View folksilva's full-sized avatar

Luiz Fernando da Silva folksilva

View GitHub Profile
@folksilva
folksilva / main.js
Created March 26, 2019 21:35
Iteração da página web remota com o Electron
// main.js - Arquivo principal do electron
// executado via npm start
const { app, BrowserWindow } = require('electron')
function createWindow () {
let win = new BrowserWindow({width: 800, height: 600})
win.loadURL("http://localhost:8000/teste.html")
}
@folksilva
folksilva / problem23.py
Created January 24, 2018 20:05
Daily Coding Problem: Problem #23
"""
This problem was asked by Google.
You are given an M by N matrix consisting of booleans that represents a board. Each True boolean represents a wall. Each False boolean represents a tile you can walk on.
Given this matrix, a start coordinate, and an end coordinate, return the minimum number of steps required to reach the end coordinate from the start. If there is no possible path, then return null. You can move up, left, down, and right. You cannot move through walls. You cannot wrap around the edges of the board.
For example, given the following board:
[[f, f, f, f],
@folksilva
folksilva / problem22.py
Created January 23, 2018 20:02
Daily Coding Problem: Problem #22
"""
This problem was asked by Microsoft.
Given a dictionary of words and a string made up of those words (no spaces), return the original sentence in a list. If there is more than one possible reconstruction, return any of them. If there is no possible reconstruction, then return null.
For example, given the set of words 'quick', 'brown', 'the', 'fox', and the string "thequickbrownfox", you should return ['the', 'quick', 'brown', 'fox'].
Given the set of words 'bed', 'bath', 'bedbath', 'and', 'beyond', and the string "bedbathandbeyond", return either ['bed', 'bath', 'and', 'beyond] or ['bedbath', 'and', 'beyond'].
https://dailycodingproblem.com/
@folksilva
folksilva / problem21.py
Last active November 27, 2020 18:24
Daily Coding Problem: Problem #21
"""
This problem was asked by Snapchat.
Given an array of time intervals (start, end) for classroom lectures (possibly overlapping), find the minimum number of rooms required.
For example, given [(30, 75), (0, 50), (60, 150)], you should return 2.
https://dailycodingproblem.com/
"""
import itertools
@folksilva
folksilva / problem5.py
Last active June 19, 2018 21:29
Daily Coding Problem: Problem #5
"""
This problem was asked by Jane Street.
cons(a, b) constructs a pair, and car(pair) and cdr(pair) returns the first and last element of that pair. For example, car(cons(3, 4)) returns 3, and cdr(cons(3, 4)) returns 4.
Given this implementation of cons:
def cons(a, b):
return lambda f : f(a, b)
Implement car and cdr.
@folksilva
folksilva / problem4.py
Created January 5, 2018 17:22
Daily Coding Problem: Problem #4
"""
This problem was asked by Stripe.
Given an array of integers, find the first missing positive integer in linear time and constant space. In other words, find the lowest positive integer that does not exist in the array. The array can contain duplicates and negative numbers as well.
For example, the input [3, 4, -1, 1] should give 2. The input [1, 2, 0] should give 3.
You can modify the input array in-place.
https://dailycodingproblem.com/
@folksilva
folksilva / problem3.py
Created January 4, 2018 20:19
Daily Coding Problem: Problem #3
"""
This problem was asked by Google.
Given the root to a binary tree, implement serialize(root), which serializes the tree into a string, and deserialize(s), which deserializes the string back into the tree.
https://dailycodingproblem.com/
"""
class Node:
def __init__(self, value):
@folksilva
folksilva / problem2.py
Last active July 19, 2018 16:37
Daily Coding Problem: Problem #2
"""
This problem was asked by Uber.
Given an array of integers, return a new array such that each element at index i of the new array is the product of all the numbers in the original array except the one at i. Solve it without using division and in O(n) time.
For example, if our input was [1, 2, 3, 4, 5], the expected output would be [120, 60, 40, 30, 24]. If our input was [3, 2, 1], the expected output would be [2, 3, 6].
https://dailycodingproblem.com/
"""
@folksilva
folksilva / problem1.py
Last active February 28, 2022 13:39
Daily Coding Problem: Problem #1
"""
This problem was asked by Google.
Given a stack of N elements, interleave the first half of the stack with the second half reversed using only one other queue. This should be done in-place.
Recall that you can only push or pop from a stack, and enqueue or dequeue from a queue.
For example, if the stack is [1, 2, 3, 4, 5], it should become [1, 5, 2, 4, 3]. If the stack is [1, 2, 3, 4], it should become [1, 4, 2, 3].
Hint: Try working backwords from the end state.
@folksilva
folksilva / women_day.py
Last active March 8, 2017 13:14
Homage to the International Women's Day
#!/usr/bin/env python
def women_day():
print(" ." + (":" * 3) + "." + (" " * 3) + "." + (":" * 3) + ".")
print((":" * 7) + "." + (":" * 7))
print(":" * 15)
print("'" + (":" * 13) + "'")
print((" " * 2) + "'" + (":" * 9) + "'")
print((" " * 4) + "'" + (":" * 5) + "'")
print((" " * 6) + "':'")