Skip to content

Instantly share code, notes, and snippets.

@tykurtz
tykurtz / grokking_to_leetcode.md
Last active July 22, 2024 17:17
Grokking the coding interview equivalent leetcode problems

GROKKING NOTES

I liked the way Grokking the coding interview organized problems into learnable patterns. However, the course is expensive and the majority of the time the problems are copy-pasted from leetcode. As the explanations on leetcode are usually just as good, the course really boils down to being a glorified curated list of leetcode problems.

So below I made a list of leetcode problems that are as close to grokking problems as possible.

Pattern: Sliding Window

#!/usr/bin/awk -f
# This program is a copy of guff, a plot device. https://github.com/silentbicycle/guff
# My copy here is written in awk instead of C, has no compelling benefit.
# Public domain. @thingskatedid
# Run as awk -v x=xyz ... or env variables for stuff?
# Assumptions: the data is evenly spaced along the x-axis
# TODO: moving average
void main() {
vec2 pos = uv(); // origin is in center
float r = sin(time + pos.x);
// x is left to right, why we see red moving from right to left think about us as a camera moving around
// sin returns a number from -1 to 1, and colors are from 0 to 1, so it clips to no red half the time
float g = sin(-time + pos.y * 20.); // higher frequency green stripes
// Define some constants
const int steps = 128; // This is the maximum amount a ray can march.
const float smallNumber = 0.001;
const float maxDist = 10.; // This is the maximum distance a ray can travel.
float scene(vec3 position){
// So this is different from the normal sphere equation in that I am
// splitting the position into it's three different parts
// and adding a 10th of a cos wave to the x position so it oscillates left
float scene(vec3 pos){
float s = length(pos) - 0.4;
return s;
}
void main() {
// Define some constants
const int steps = 128; // This is the maximum amount a ray can march.
const float smallNumber = 0.001;
const float maxDist = 10.; // This is the maximum distance a ray can travel.
float scene(vec3 position){
// So this is different from the prev sphere equation in that I am
// splitting the position into it's three different parts
// and adding a 10th of a cos wave to the x position so it oscillates left
// http://www.iquilezles.org/www/articles/palettes/palettes.htm
// As t runs from 0 to 1 (our normalized palette index or domain),
//the cosine oscilates c times with a phase of d.
//The result is scaled and biased by a and b to meet the desired constrast and brightness.
vec3 cosPalette( float t, vec3 a, vec3 b, vec3 c, vec3 d )
{
return a + b*cos( 6.28318*(c*t+d) );
}
float sphere(vec3 pos, float rad){
const int step = 128;
const float maxDist = 10.3;
const float smallNumber = 0.02;
// http://www.iquilezles.org/www/articles/palettes/palettes.htm
// As t runs from 0 to 1 (our normalized palette index or domain),
//the cosine oscilates c times with a phase of d.
//The result is scaled and biased by a and b to meet the desired constrast and brightness.
vec3 cosPalette( float t, vec3 a, vec3 b, vec3 c, vec3 d )
{
#ifdef GL_ES
precision highp float;
#endif
// These are defined by Kodelife, or whatever environment you are using.
uniform float time;
uniform vec2 resolution;
varying vec3 v_normal;
varying vec2 v_texcoord;
# its dependencies are gifsicle and ffmpeg
gifify() {
if [[ -n "$1" ]]; then # if the input lengt≈h is non-zero
randomPlace=0 #lazy, i use it for filename regurdless if its needed or not
if [[ $2 != '--random' && $3 != '--random' ]]; then
ffmpeg -i $1 -r 10 -vcodec png out-static-%05d.png
else
#s=$(ffprobe -i $1 -show_entries format=duration -v quiet -of csv="p=0")
s=$(ffprobe -i $1 -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1)
seconds=$(echo "$s - 2" | bc)