Skip to content

Instantly share code, notes, and snippets.

View alxfv's full-sized avatar

Alexander Fedorov alxfv

View GitHub Profile
@alxfv
alxfv / producer-consumer.go
Created April 13, 2019 15:39
Producer-consumer in Golang
package main
import (
"fmt"
"math/rand"
"time"
)
const (
N = 20
import sys
def read_line():
return sys.stdin.readline().split()
def read_int_iter():
return map(int, read_line())
class Solution:
def corpFlightBookings(self, bookings: List[List[int]], n: int) -> List[int]:
prefix_sum = [0] * (n + 1)
# 1. Build prefix sum array
# for booking [1, 3, 5] and n = 5 prefix sum array:
# [0, 0, 0, 0, 0] -> [5, 0, 0, -5, 0, 0]
for lo, hi, seats in bookings:
prefix_sum[lo - 1] += seats
def isValid(node, floor, ceiling):
if not node:
return True
if not floor < node.val < ceiling:
return False
return isValid(node.left, floor, node.val) and isValid(node.right, node.val, ceiling)
@alxfv
alxfv / pypy2_competitive_template.py
Created April 4, 2020 14:01
PyPy2 Python Competitive Template: Fast IO + unittest
# <editor-fold desc="Fast IO">
# !/usr/bin/env python
from __future__ import division, print_function
import os
import random
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
@alxfv
alxfv / backspace_string_compare.py
Created April 9, 2020 08:33
Backspace String Compare
class Solution:
def backspaceCompare(self, S: str, T: str) -> bool:
def next_index(R: str, i: int) -> int:
"""
Get the index of the next undeleted letter
@param R: str string
@param i: index
@return: current letter index
"""
@alxfv
alxfv / backspace_string_compare.py
Last active April 9, 2020 09:06
Backspace String Compare
class Solution:
def backspaceCompare(self, *all_strings) -> bool:
def next_index(s: str, i: int) -> int:
"""
Get the index of the next undeleted letter
@param R: str string
@param i: index
@return: current letter index
"""
from sys import getsizeof
from timeit import timeit
bitset = 0
N = 100000
def populate_bitset():
global bitset