This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
promos = [globals()[name] for name in globals() | |
if name.endswith('_promo') | |
and name != 'best_promo'] | |
def best_promo(order): | |
return max(promo(order) for promo in promos) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from abc import ABC, abstractmethod | |
from collections import namedtuple | |
Customer = namedtuple('Customer', 'named fidelity') | |
class LineItem: | |
def __init__(self, product, quantity, price): | |
self.product = product | |
self.quantity = quantity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from abc import ABC, abstractmethod | |
from collections import namedtuple | |
Customer = namedtuple('Customer', 'named fidelity') | |
class LineItem: | |
def __init__(self, product, quantity, price): | |
self.product = product | |
self.quantity = quantity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from threading import Thread | |
COUNT = 50000000 | |
def countdown(n): | |
while n>0: | |
n -= 1 | |
t1 = Thread(target=countdown, args=(COUNT//2,)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from threading import Thread | |
COUNT = 50000000 | |
def countdown(n): | |
while n>0: | |
n -= 1 | |
start = time.time() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define MAX_N 100001 | |
typedef struct { | |
int first; | |
int second; | |
} pii; | |
struct pq{ | |
pii heap[MAX_N]; | |
int index[MAX_N]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
private: | |
bool hash[500001] = {0, }; | |
public: | |
int firstMissingPositive(vector<int>& nums) { | |
int cnt; | |
for (int i=0; i<nums.size(); i++){ | |
if(nums[i] <= 0 || nums[i] > nums.size()) continue; | |
else hash[nums[i]] = true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Data{int idx; int value;}; | |
Data db[MAX_N]; | |
int pri[MAX_N]; | |
priority_queue<pair<int, Data*>> PQ; | |
void find(){ | |
while(!PQ.empty()){ | |
int pri = PQ.top().first; | |
Data *p = PQ.top().second; | |
PQ.pop(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Data{int value; bool flag;}; | |
Data db[MAX_N]; | |
priority_queue<Data*> PQ; | |
void find(){ | |
Data *p; | |
while(!PQ.empty()){ | |
p = PQ.top(); | |
PQ.pop(); | |
if(!p->flag) continue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <queue> | |
#include <vector> | |
using namespace std; | |
class MedianFinder { | |
private: | |
struct comp_min{bool operator()(int &a, int &b){return a > b;}}; | |
struct comp_max{bool operator()(int &a, int &b){return a < b;}}; | |
priority_queue<int, vector<int>, comp_min> rightQ; // [n/2, n] | |
priority_queue<int, vector<int>, comp_max> leftQ; // [0, n/2-1] |
NewerOlder