I hereby claim:
- I am lopespm on github.
- I am lopespm (https://keybase.io/lopespm) on keybase.
- I have a public key ASBVOGTQ7FFo3e2z4-HGjCwpsxKjqroop4en_wFUDWevBwo
To claim this, I am signing this object:
# (Variant #6 for exercise 5.18 on EPI (Elements of Programming Interviews)) (September 2018 edition) | |
# Consider a 10x7 (mxn) matrix, in which we get 30 elements for the the outer ring, the next outer ring would have 22 elements, then 14 elements, and the most inner ring has the remaining elements. The number of elements per ring is given by 2 x (m - (1 + (2 x (r-1) ))) + 2 x (n - (1 + (2 x (r-1) ))), for the rth ring. | |
# Save from the most inner ring, the difference between the number of elements of each adjacent ring is 8 elements. If we want to know the number of elements of the current ring plus all the other previous ones, we get an arithmetic series (https://en.wikipedia.org/wiki/Arithmetic_progression#Sum). | |
# The sum of all the elements until a given r is given by sum = (r(a1 + ar)) / 2, being a1 = 2(m-1) + 2(n-1), ar = 2 x (m - (1 + (2 x (r-1) ))) + 2 x (n - (1 + (2 x (r-1) ))). If we solve the equation in relation to r, using the quadratic formula to disentangle the final polynomial, we reach r = mat |
# Print tree by levels - using BFS | |
# The idea behind it is to use BFS and keep a level marker integer which marks the end the last node of the level. This is similar to Naresh's sentinel approach, but without the need of inserting a sentinel inside the queue, since this is accomplished by the level marker. | |
# Time complexity of O(n) | |
# Space complexity: O(2^tree_height) | |
from collections import deque | |
class Node: | |
def __init__(self, data, left=None, right=None): | |
self.data = data |
I hereby claim:
To claim this, I am signing this object:
# (Variant #4 for exercise 11.1 on EPI (Elements of Programming Interviews)) | |
# The rationale behind it to perform a binary search which only considers a given character index of the strings. | |
# If these are present, continue to the next character index. If any of the prefix characters cannot be found in any string, return immediatly | |
# Considering n strings and k prefix length: | |
# Time complexity: O(k * log(n)) | |
# Space complexity: O(1) | |
from typing import List | |
def first(items: List[str], prefix: str, i: int, c: str, left: int, right: int): |
# (Variant for exercise 5.1 on EPI (Elements of Programming Interviews)) | |
# The rationale behind it is to squeeze the forth color (middle right color) in between the middle left and right sub-arrays. It defines the colors as the algorithm progresses. | |
# It has a O(n) time complexity and O(1) space complexity | |
from typing import List | |
def dutch_variant_four_colors(array: List[int]) -> List[int]: | |
left = array[0] | |
mid_left = None | |
right = None |
# Returns the size of the largest binary subtree that is complete, in Python - variant for exercise 9.1 on EPI (Elements of Programming Interviews) | |
# The gist of the solution is to keep track of the subtree's current number of nodes, current height and maximum height until that point. | |
# With the current number of nodes and height, one can calculate the root's own number of nodes and height via its direct childs respective information, | |
# taking into to consideration the relation between the child heights and if they are perfect subtrees or not. | |
# Solution is O(n) time complexity and O(h) space complexity (function call stack corresponds from the root through the unique path to the current node) | |
from collections import namedtuple | |
class BTN(): |
I tried a few different techniques to make a GIF via command-line and the following gives me the best control of quality and size. Once you're all setup, you'll be pumping out GIFs in no time!
Install FFmpeg
Install ImageMagick
const assert = require('assert'); | |
const async = require('async'); | |
const fs = require('fs'); | |
let request = require('request'); | |
const FileCookieStore = require('tough-cookie-filestore'); | |
if (!fs.existsSync('cookies.json')) { fs.writeFileSync('cookies.json', '{}');} | |
let j = request.jar(new FileCookieStore('cookies.json')); | |
request = request.defaults({ jar : j }); |
#!/bin/bash | |
build_folder="build" | |
source_image="source-image.png" | |
mkdir $build_folder | |
convert $source_image -scale 16 $build_folder/16.png | |
convert $source_image -scale 32 $build_folder/32.png | |
convert $source_image -scale 48 $build_folder/48.png |