View google_kickstart_parcels.rs
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
/* | |
problem: https://codingcompetitions.withgoogle.com/kickstart/round/00000000008f4a94/0000000000b55465 | |
youtube: https://youtu.be/Yvj18KBThsE (subscribe) | |
twitter: https://twitter.com/robertkingNZ (follow) | |
*/ | |
use std::collections::VecDeque; | |
use std::usize; |
View controlled_inflation.rs
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
// video here: https://www.youtube.com/c/RobertKing/videos | |
fn dist(x: u64, y: u64) -> u64 { | |
if x <= y { | |
return y - x; | |
} | |
x-y | |
} | |
fn min(x: u64, y: u64) -> u64 { |
View chain-reactions.rs
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
/* | |
twitter: @robertkingnz | |
youtube: https://www.youtube.com/c/RobertKing/videos | |
topological sort found here: https://github.com/kenkoooo/competitive-programming-rs/blob/master/src/graph/topological_sort.rs | |
Google Code Jam 2022 Chain Reactions: https://codingcompetitions.withgoogle.com/codejam/round/0000000000876ff1/0000000000a45ef7 | |
*/ | |
pub fn topological_sort(graph: &[Vec<usize>], mut fun: Vec<u64>) -> u64 { | |
let n = graph.len(); |
View challenge-nine.rs
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
fn main() { | |
let (r, w) = (std::io::stdin(), std::io::stdout()); | |
let mut sc = IO::new(r.lock(), w.lock()); | |
let t: usize = sc.read(); | |
for case_num in 1..=t { | |
let mut v: Vec<usize> = sc.chars().into_iter().map(|c| { | |
((c as u8) - b'0') as usize | |
}).collect(); |
View h-index.rs
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
use std::cmp::Reverse; | |
fn main() { | |
let (r, w) = (std::io::stdin(), std::io::stdout()); | |
let mut sc = IO::new(r.lock(), w.lock()); | |
let t: usize = sc.read(); | |
for case_num in 1..=t { | |
let mut heap = std::collections::BinaryHeap::new(); | |
let n: usize = sc.read(); |
View fast_longest_palindromic_substring.rs
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
// @robertkingnz | |
// this rust implementation reduces the number of centers that need checking | |
// it does so by only trying one possible center for each group of repeating characters. | |
// this is one of the few 0ms solutions on leetcode, | |
// although there is a faster, more complex, O(N) solution possible. | |
impl Solution { | |
pub fn longest_palindrome(s: String) -> String { | |
let b = s.as_bytes(); | |
fn expand(mut i: usize, mut j: usize, b: &[u8]) -> (usize, usize) { |
View faster_sort.go
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
package main | |
import ( | |
"math/rand" | |
"fmt" | |
"time" | |
"sort" | |
) | |
const N = 1 << 20 |
View hashcode 2020 online qualification.py
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
# incomplete code by @robertkingNZ of team @perplexico_ | |
import sys | |
import collections | |
Library = collections.namedtuple('Library', ['id', 'signup', 'per_day', 'bookids']) | |
def get_problem_from_file(f): | |
lines = (line for line in f.read().splitlines()) | |
rows = (list(map(int, line.split())) for line in lines) |
View shutdown_servers.py
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
# given matrix of servers, servers connect to servers in their row or column. 'C' denotes a server computer. | |
# shutdown the servers in an order such that shutdown servers pass their data on to nearby servers, such that | |
# the minimum number of servers need to stay on. | |
# author: @robertkingnz | |
def make(): | |
M = [] | |
rows = 10 | |
cols = 20 |
NewerOlder