This file contains hidden or 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
MOD = 10 ** 9 + 7 | |
def modpow(x, y, mod): | |
elems = [] | |
while y: | |
elems.append(y % 2) | |
y >>= 1 | |
el = len(elems) | |
x_pows = [x for _ in xrange(el)] |
This file contains hidden or 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
def circle_check(graph): | |
n = len(graph) | |
graph = [list(node.keys()) for node in graph] | |
indexes = [0] * n | |
stack = [0] | |
visited = [False] * n | |
visited[0] = True | |
while stack: | |
curr = stack[-1] |
This file contains hidden or 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
{ | |
"size": 0, | |
"query": { | |
"bool": { | |
"must": [ | |
{ "exists": {"field": "status" } }, | |
{ "exists": {"field": "class_name" } }, | |
{ "exists": {"field": "test_name" } } | |
] | |
} |
This file contains hidden or 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
package main | |
import ( | |
"bufio" | |
"fmt" | |
"log" | |
"math" | |
"strconv" | |
"strings" | |
) |
This file contains hidden or 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 <map> | |
#include <utility> | |
#include <vector> | |
#include <algorithm> | |
#include <iostream> | |
#include <iomanip> | |
using namespace std; | |
typedef long long ll; |
This file contains hidden or 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
// Compile and run with g++ -o vjoin --std=c++17 variadic_join.cc; ./vjoin | |
// c++17 standard might not be needed since we use the c++11 variadic template notation | |
#include <bits/stdc++.h> | |
using namespace std; | |
using ll = long long; | |
template<typename T> | |
void join(stringstream &ss, const string &sep, T t) { | |
ss << t; | |
} |
This file contains hidden or 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 <bits/stdc++.h> | |
using namespace std; | |
using ll = long long; | |
constexpr ll mod = 1000000007; | |
ll fast_pow_mod(ll a, ll b, ll m) { | |
a %= m; | |
if(a == 0ll) return a; |
This file contains hidden or 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 <bits/stdc++.h> | |
using namespace std; | |
using ll = long long; | |
constexpr ll p = 1000000007; | |
ll gcd(ll a, ll b) { | |
while(b) { | |
ll tmp = b; |
This file contains hidden or 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
use std::cmp; | |
pub fn smaller(vec: &Vec<i32>, val: i32) -> i32 { | |
let len = vec.len(); | |
if(len == 0) { | |
return 0; | |
} | |
if vec[len - 1] < val { | |
return len as i32; |
This file contains hidden or 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
use std::vec::Vec; | |
impl Solution { | |
pub fn multiply(num1: String, num2: String) -> String { | |
let one: Vec<u32> = num1.chars().map(|c| c.to_digit(10).unwrap()).rev().collect(); | |
let other: Vec<u32> = num2.chars().map(|c| c.to_digit(10).unwrap()).rev().collect(); | |
let mut tmp: Vec<u32> = vec![0; one.len() + other.len() + 1]; | |
for (i, el1) in one.iter().enumerate() { |