Skip to content

Instantly share code, notes, and snippets.

@venkatsgithub1
venkatsgithub1 / grokking_to_leetcode.md
Created January 8, 2023 12:02 — 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

import java.util.Arrays;
import static com.mongodb.client.model.Filters.eq;
import static com.mongodb.client.model.Aggregates.group;
import static com.mongodb.client.model.Accumulators.sum;
Arrays.asList(group(eq("$substr", Arrays.asList("$title", 3L, -1L)), sum("count", 1L)));
@venkatsgithub1
venkatsgithub1 / dereferencing.js
Created February 10, 2020 10:45
Sample code to show dereferencing
const person = {
first: 'John',
last: 'Doe',
country: 'India',
city: 'Bengaluru'
};
func1 = (data) => {
console.log({ data });
}
@venkatsgithub1
venkatsgithub1 / main_1.py
Last active June 4, 2019 01:16
Loading a json file and writing to csv in python 2.7.15
import json
import csv
with open('./test.json', 'r') as f1:
# read data as string.
data_json = f1.read()
# loads method converts string data into dictionary.
dict1=json.loads(data_json)
print dict1
# accessing data
@venkatsgithub1
venkatsgithub1 / main_1.py
Last active May 29, 2019 18:20
Loading a json file and writing to csv in python
import json
import csv
with open('./test.json', 'r') as f1:
# read data as string.
data_json = f1.read()
# loads method converts string data into dictionary.
dict1=json.loads(data_json)
print(dict1)
# accessing data
@venkatsgithub1
venkatsgithub1 / plain_requests.py
Last active May 26, 2018 06:49
A small test on requests with and without multiprocessing.
import requests
import time
url = 'https://xkcd.com/'
url_data = []
start = time.time()
for i in range(1821, 1831):
@venkatsgithub1
venkatsgithub1 / MySQLConnectionExample1.py
Created October 23, 2017 17:16
Using Python to connect to MySQL database.
class UseMySQL:
# Importing MySQLdb and as a smaller name for reusing it.
# To install MySQL Python connection use below command:
# pip install mysqlclient
import MySQLdb as _mysql
def __init__(self, host, user, password, db):
"""
Initializing MySQL details in init method.
@venkatsgithub1
venkatsgithub1 / MyLambda1.java
Created October 22, 2017 14:04
A small introduction to lambdas in Java: MyLambda1 class
package demo.java.lambdas;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class MyLambda1 {
public static void main(String[] args) {
@venkatsgithub1
venkatsgithub1 / Person.java
Created October 22, 2017 14:03
A small introduction to lambdas in Java: Person class
package demo.java.lambdas;
public class Person {
private String name;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
@venkatsgithub1
venkatsgithub1 / MyLambdalessExample.java
Created October 22, 2017 14:00
A small introduction to lambdas in Java: Class without lambdas
package demo.java.lambdas;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
public class MyLambdalessExample {
public static void main(String[] args) {
List<Person> personList = new ArrayList<>();