Skip to content

Instantly share code, notes, and snippets.

from calendar import c
from typing import List
# given students heights, find number of students who can see teacher standing on the right.
# (within context of the previous task) find an index of the student whom we could move to the back to maximize the number of students who can see the teacher standing on the right.
class Solution:
def find(self, heights: List[int]):
prev_height = -1
package main
import (
"encoding/json"
log "github.com/sirupsen/logrus"
"io/ioutil"
"net"
"flag"
"net/http"
)
package main
import (
"fmt"
"sync"
"time"
)
func main() {
lessFriendly := throttleLoad(
@vkozubal
vkozubal / tunnel_my_ass.sh
Last active October 25, 2019 11:26
Inspired by Alex Myasoedov
si () {
instances=$(aws ec2 describe-instances \
--query 'Reservations[].Instances[].[InstanceId, Tags[?Key==`Project`]|[0].Value, Tags[?Key==`Component`]|[0].Value, State.Name]' \
--filter Name=tag:Environment,Values=$@ \
--output text)
if [ $? -ne 0 ]
then
echo failed to list instances
return
fi
@vkozubal
vkozubal / robot_programming_strategy.py
Created May 7, 2019 20:27
Round 1C Google Code Jam 2019
import collections
def solve_c(programs, index=0):
reg = collections.defaultdict(list)
for program in programs:
reg[program[index % len(program)]].append(program)
moves = list(reg.keys())
@vkozubal
vkozubal / golf_gophers.py
Created April 25, 2019 16:58
Round 1A 2019 - Google Code Jam 2019
#!/usr/bin/env python
all_primes = [5, 7, 9, 11, 13, 16, 17]
# the number of test cases, the number of nights allowed per test case and the maximum number of gophers, respectively
T, N, M = map(int, input().split(" "))
def filter(number, remainder, generator):
for candidate in generator:
@vkozubal
vkozubal / AlienRhyme.py
Last active April 25, 2019 15:13
Google hash code 2019 round 1A
import collections
def solve(N: int):
words = [input()[::-1] for _ in range(N)] # reversed
d = collections.defaultdict(list)
index = 0
for word in words:
d[word[index]].append(word)
@vkozubal
vkozubal / youcangoyourownway.py
Last active May 7, 2019 20:29
You can go your own way
def solution(n: int, path: str):
d = {
'S': 'E',
'E': 'S',
}
return "".join(map(d.get, path))
for t in range(1, int(input()) + 1):
size = int(input())
path = solution(size-1, input())
@vkozubal
vkozubal / foregone.py
Last active May 7, 2019 20:29
Foregone
def solution(inp):
i, first, second = 0, 0, 0
scale = 1
while inp:
digit = inp % 10
inp = inp // 10
first_digit, second_digit = (2, 2) if digit == 4 else (digit, 0)
first += scale * first_digit
@vkozubal
vkozubal / flatten_soted_iterators.py
Last active May 19, 2019 18:50
Merges iterators and presumes ordering
import heapq
class HeapElem:
def __init__(self, val: int, iter):
self.iter = iter
self.val = val
def __lt__(self, other):
return self.val < other.val