Skip to content

Instantly share code, notes, and snippets.

View payal-kothari's full-sized avatar

Payal Ajit Kothari payal-kothari

  • Credit Karma Inc.
  • San Francisco, CA
View GitHub Profile

Sublime Text 2 - Useful Shortcuts

Tested in Mac OS X: super == command

Open/Goto


  • super+t: go to file
  • super+ctrl+p: go to project
  • super+r: go to methods
@payal-kothari
payal-kothari / "val"_and_"def".scala
Last active June 29, 2018 22:51
Scala - From "Essential Scala" book
// "def a" and "def c" are methods
// methods are executed for every separate call
// "val b" val so it will be executed only in the beginning and after that for every call the stored value will be used
object argh {
def a = {
println("a")
1
@payal-kothari
payal-kothari / Grid illumination.java
Created January 18, 2018 23:18
Given an NxN grid with an array of lamp coordinates. Each lamp provides illumination to every square on their x axis, every square on their y axis, and every square that lies in their diagonal (think of a Queen in chess). Given an array of query coordinates, determine whether that point is illuminated or not. The catch is when checking a query a…
public class Lamps{
private boolean[] columns, rows, diagonalsLeft, diagonalsRight;
public Lamps(int size, int[][] lamps){
this.columns = new boolean[size];
this.rows = new boolean[size];
this.diagonalsLeft = new int[(size) * 2 - 2]; or (size - 1) * 2 + 1
this.diagonalsRight = new int[(size) * 2 - 2];
@payal-kothari
payal-kothari / Grid illumination.java
Created January 18, 2018 23:18
Given an NxN grid with an array of lamp coordinates. Each lamp provides illumination to every square on their x axis, every square on their y axis, and every square that lies in their diagonal (think of a Queen in chess). Given an array of query coordinates, determine whether that point is illuminated or not. The catch is when checking a query a…
public class Lamps{
private boolean[] columns, rows, diagonalsLeft, diagonalsRight;
public Lamps(int size, int[][] lamps){
this.columns = new boolean[size];
this.rows = new boolean[size];
this.diagonalsLeft = new int[(size) * 2 - 2]; or (size - 1) * 2 + 1
this.diagonalsRight = new int[(size) * 2 - 2];
@payal-kothari
payal-kothari / The Technical Interview Cheat Sheet.md
Created January 18, 2018 21:16 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
Collections.sort(sList, (p1, p2) ->p2.getDOB().compareTo(p1.getDOB()));
public class Solution {
// you need to treat n as an unsigned value
public static int hammingWeight(int n) {
int count = 0;
while(n!=0) {
int check = n & 1;
count = count + check;
n = n>>>1; // zero filled right shift, eventually the no. "n" will become zero
}
return count;
// recursive
public class Solution {
int goal;
double min = Double.MAX_VALUE;
public int closestValue(TreeNode root, double target) {
helper(root, target);
return goal;
}