Skip to content

Instantly share code, notes, and snippets.

@summit87
summit87 / latency.txt
Created December 23, 2020 12:58 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
package com.practice.backtracking.tree;
public class MaxConsecutiveLength {
public static void main(String[] args) {
BT bt = new BT(10);
bt.setLeft(new BT(1));
bt.setRight(new BT(9));
bt.getLeft().setLeft(new BT(13));
bt.getLeft().setRight(new BT(12));
package com.practice.backtracking.mattrix;
public class RowWithMax1s {
public static void main(String[] args) {
int[][] mat = {{0, 0, 0, 1},
{0, 0, 0, 0},
{0, 0, 0, 1},
{0, 1, 1, 1}
};
@summit87
summit87 / FindPairSumInRotatedArray.java
Last active August 12, 2019 19:56
FindPairSumInRotatedArray
package com.practice.backtracking.array;
public class FindPairSumInRotatedArray {
public static void main(String[] args) {
int[] a = {11, 15, 6, 7, 9, 10};
int sum = 16;
System.out.println(isSumExist(a,findPivot(a, 0, a.length - 1),sum));
}
@summit87
summit87 / GenerateAllRotation.java
Created August 11, 2019 18:08
GenerateAllRotation of a given number
public class GenerateAllRotation {
public static void main(String[] args) {
generateRotation(1445);
}
private static int len(int num){
int count=0;
while (num >0){
count++;
package com.algo.ds.practice.TreePractice;
import com.algo.ds.practice.TreeNode;
import java.util.HashSet;
import java.util.Set;
public class VerticalWidth {
public static void main(String[] args) {
TreeNode tn = new TreeNode(1);
package mattrix;
import java.util.LinkedList;
import java.util.Queue;
public class RotTomato {
public static void main(String[] args) {
//
int[][] mat = {{2, 1, 0, 2, 1}, {1, 0, 1, 2, 1}, {1, 0, 0, 2, 1}};
int row = 3;
package app;
public class GetPairInRotatedArray {
public static void main(String[] args) {
int[] a = { 11, 15, 26, 38, 9, 10 };
int hi = getIndex(a, 0, a.length - 1);
int low = hi + 1;
System.out.println(isSumExist(a, hi, low, 35));
}
package com.test.string;
public class Amazon392Mattrix {
public static void main(String[] args) {
char[][] mat = {{'a','b','c'},{'d','e','f'},{'g','h','i'}};
int row = 3;
int col = 3;
mattrix(mat,row,col);
}
package array;
public class Swap {
public static void main(String[] args) {
int[] a = {-1, -2, -3, -4, 5, 6, -7, 8, 9};
quickSort(a,0,a.length-1);
for (int i : a){
System.out.print(i+",");
}