This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Latency Comparison Numbers | |
-------------------------- | |
memory L1 cache reference 0.5 ns | |
memory Branch mispredict 5 ns | |
memory L2 cache reference 7 ns 14x L1 cache | |
memory Mutex lock/unlock 25 ns | |
memory Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
network Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
disk Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://www.quora.com/Isnt-dynamic-programming-much-simpler-coding-in-languages-like-Python-and-others-rather-than-Java-C-C++ | |
# https://docs.python.org/3/library/functools.html | |
$ python3 | |
Python 3.4.2 (default, Oct 19 2014, 17:52:17) | |
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.51)] on darwin | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> from functools import lru_cache | |
>>> @lru_cache(maxsize=None) | |
... def fib(n): | |
... if n < 2: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat a.py | |
class A(object): | |
def __init__(self): | |
pass | |
$ python | |
Python 2.7.8 |Anaconda 2.1.0 (64-bit)| (default, Aug 21 2014, 18:22:21) | |
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2 | |
Type "help", "copyright", "credits" or "license" for more information. | |
Anaconda is brought to you by Continuum Analytics. | |
Please check out: http://continuum.io/thanks and https://binstar.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mport java.util.ArrayList; | |
import java.util.List; | |
import java.util.Scanner; | |
public class Solution { | |
public static String numOfStones(final int n, final int a, final int b) { | |
int small = a; | |
int big = b; | |
if ( b < a) { | |
small = b; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mport java.math.BigInteger; | |
import java.util.Scanner; | |
public class Solution { | |
public static void main(final String[] args) { | |
Scanner sc = new Scanner(System.in); | |
String[] input = sc.nextLine().split(" "); | |
final int numOfJars = Integer.parseInt(input[0]); | |
final int numOfOps = Integer.parseInt(input[1]); | |
BigInteger totalNumOfCandies = new BigInteger("0"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 5 | |
10101 | |
11100 | |
11010 | |
00101 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.Scanner; | |
public class Solution { | |
public static String canBuildPalindrome(final String s) { | |
Map<Character, Integer> m = new HashMap<Character, Integer>(); | |
int odd_cnt = 0; | |
for ( int i = 0; i < s.length(); ++i ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.List; | |
import java.util.Scanner; | |
public class Solution { | |
public static int distributionOfCandies(final int K, final List<Integer> packets) { | |
int min = Integer.MAX_VALUE; | |
Collections.sort(packets); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Solution { | |
public static int numOfReduction(final String s) { | |
int cnt = 0; | |
int l = 0; | |
int r = s.length() - 1; | |
while ( l < r ) { | |
int lNum = s.charAt(l); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Test { | |
public static int numOfDeletion(final String s) { | |
int cnt = 0; | |
char prev = s.charAt(0); | |
for ( int i = 1; i < s.length(); ++i ) { | |
char c = s.charAt(i); | |
if ( prev == c ) |
NewerOlder