Skip to content

Instantly share code, notes, and snippets.

View idfumg's full-sized avatar

Artem Pushkin idfumg

View GitHub Profile
#include <iostream>
#include <unordered_map>
#include <list>
#include <optional>
#include <cassert>
using namespace std;
template <class T>
concept Hashable = requires(T param) { std::hash<T>()(param); };
from typing import TypeAlias, Tuple, Hashable, TypeVar, Generic
FrequencyT: TypeAlias = int
ValueT = TypeVar("ValueT")
ValueFrequencyT: TypeAlias = tuple[ValueT, FrequencyT]
KeyT = TypeVar("KeyT", bound=Hashable)
KeysT: TypeAlias = set[KeyT]
package main
import "fmt"
type Set[T comparable] struct {
items map[T]struct{}
}
func NewSet[T comparable]() *Set[T] {
return &Set[T]{
#include <iostream>
#include <stdexcept>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <optional>
#include <cassert>
using namespace std;
@idfumg
idfumg / pg-docker-compose.yml
Last active April 13, 2024 09:31
Postgresql docker compose file for testing purposes.
version: '3'
services:
postgres:
image: 'postgres:14.5'
container_name: "postgres_isolation"
restart: always
environment:
- POSTGRES_DB=isolation_levels
[Connection]
brew install pgcli
pgcli -h localhost -p 5432 -U postgres isolation_levels # password postgres
[Preparation]
DROP TABLE IF EXISTS accounts;
CREATE TABLE accounts (
id SERIAL PRIMARY KEY,
const (
INF = int(1e9)
)
func maxProfit(prices []int) int {
cache := createCache(len(prices), -1)
return run(0, 0, prices, cache)
}
func createCache[T any](N int, val T) [][]T {
const (
INF = int(1e9)
)
var (
cache [100001][2]int
)
func maxProfit(nums []int) int {
initCache(len(nums), -1)
const (
INF = int(1e9)
)
var (
cache [100001][2]int
nums [100001]int
N int
)
static int INF = 1e9+7;
static int N = 0;
static vector<int> nums;
static int cache[100001][2];
static void init(vector<int>& prices) {
N = size(prices);
nums.resize(N);
for (int i = 0; i < N; ++i) {
nums[i] = prices[i];