Skip to content

Instantly share code, notes, and snippets.

@collegian
collegian / grokking_to_leetcode.md
Created June 19, 2022 15:54 — forked from tykurtz/grokking_to_leetcode.md
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

@collegian
collegian / groupBy.js
Created October 14, 2020 22:24 — forked from robmathers/groupBy.js
A more readable and annotated version of the Javascript groupBy from Ceasar Bautista (https://stackoverflow.com/a/34890276/1376063)
var groupBy = function(data, key) { // `data` is an array of objects, `key` is the key (or property accessor) to group by
// reduce runs this anonymous function on each element of `data` (the `item` parameter,
// returning the `storage` parameter at the end
return data.reduce(function(storage, item) {
// get the first instance of the key by which we're grouping
var group = item[key];
// set `storage` for this instance of group to the outer scope (if not empty) or initialize it
storage[group] = storage[group] || [];
@collegian
collegian / iTerm2.md
Created October 2, 2020 15:38 — forked from soifou/iTerm2.md
iTerm2 Shortcuts

iTerm2 Shortcuts

Tab navigation

  • open new tab: Cmd + t
  • next tab: Cmd + Shift + ]
  • previous tab: Cmd + Shift + [

Pane navigation

@collegian
collegian / Decode.java
Last active October 4, 2019 11:18
Decode
package lc.dp;
import java.util.ArrayList;
import java.util.List;
public class Decode
{
public int numDecodings(String s)
{
if(s.equals("0"))
@collegian
collegian / GroupAnagrams.java
Created September 24, 2019 17:55
Group anagrams sans sorting
void groupAnagrams(String[] str)
{
Map<String,List<String>> lst = new HashMap<String, List<String>>();
for(String s:str)
{
int[] charCnt = new int[26];
for(char x:s.toCharArray())
{
charCnt[x-'a']++;
}
@collegian
collegian / FindRectangleZeros.js
Created June 2, 2019 22:12
Wfr find all rectangle containing zeros in an image
var rectangle = function findRectangle(image)
{
var indexSeen = new Set();
var allResults = [];
for(let i=0;i<image.length;i++)
{
for(let j=0;j<image.length;j++)
{
if(image[i][j]===0 && !indexSeen.has((image.length*i)+j))
@collegian
collegian / MakeChangesWays.java
Created October 4, 2018 02:51
Number of ways to make change for an amount using infinite number of coins
package recursionAndDP;
import java.util.Arrays;
import java.util.List;
public class MakeChangesWays
{
// Idea is to construct an array of all the amounts and the ways to reach each of the amounts using each
// of the existing coins. To reach amount 0 we have 1 way.
public void makeChange(List<Integer> coins, int n)
@collegian
collegian / InnerClass.java
Created September 16, 2018 17:16
Inner class and Nested class usage.
package misc;
public class InnerClass
{
public Inn greet()
{
System.out.println("Greetings to you");
// This is how typically an inner class is instantiated. The other option is
// to use the enclosing class instance but this is better.
return new Inn();