Skip to content

Instantly share code, notes, and snippets.

View hesic73's full-sized avatar

Sicheng He hesic73

View GitHub Profile
@hesic73
hesic73 / median_heap.cpp
Created February 7, 2024 09:19
A data structure designed to perform median finding in constant time. This implementation is part of the solution for Question 1, Homework 4, in the CSCI 570 course during the Spring 2024 semester at the University of Southern California.
/*
* C++20 Standard Required
* Author: Sicheng He
* Date: 2024-02-06
*/
#include<iostream>
#include<queue>
#include<vector>
#include<concepts>
#include<optional>
@hesic73
hesic73 / Solution.java
Created February 5, 2024 01:21
Template for 2D Grid Problems on LeetCode
import java.util.Iterator;
import java.util.NoSuchElementException;
class Solution {
private static boolean withBounds(int x, int y, int m, int n) {
return x >= 0 && x < m && y >= 0 && y < n;
}
private static int flatten(int x, int y, int m, int n) {
@hesic73
hesic73 / MyArrayDeque.java
Last active February 8, 2024 20:37
An enhanced ArrayDeque enabling indexed access and modification
import java.util.*;
import java.util.function.Consumer;
/**
* An enhanced ArrayDeque enabling indexed access and modification via {@code get(int index)} and {@code set(int index, E e)} methods.
* The majority of this implementation is directly borrowed from the official ArrayDeque.
*
* @param <E> the type of elements held in this collection
*/
public class MyArrayDeque<E> extends AbstractCollection<E> implements Deque<E> {
@hesic73
hesic73 / topological_orderings.cpp
Last active February 3, 2024 23:35
All possible topological orderings
#include<iostream>
#include<vector>
#include<set>
// we assume that for the same elements, the iteration order is always the same
// which is not the case for unordered_map
void _topological_ordering(std::set<int>& s,
std::vector<int>& v,