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 akka.actor.{DeadLetter, ActorSystem, Props, Actor} | |
class Actor1 extends Actor{ | |
override def preStart() { | |
context.actorOf(Props[Actor2], "actor2") | |
context.system.eventStream.subscribe(self, classOf[DeadLetter]) | |
} | |
def receive = { | |
case x => | |
println(x) |
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
/** This does not replicate getting ReceiveTimeout after cancelling - how to replicate? | |
* | |
* It seems like the only way it would happen is if setReceiveTimeout(Undefined) was called outside | |
* of the actor's receive block. Otherwise with this at the end of ActorCell invoke(): | |
* | |
* } finally { | |
* checkReceiveTimeout // Reschedule receive timeout | |
* } | |
* | |
* checkReceiveTimeout would always know to *not* schedule a new ReceiveTimeout |
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
/** | |
* Determine if both arrays of keys would form the same BSTs | |
* without building the trees | |
*/ | |
def isSameBST(arr1: Array[Int], arr2: Array[Int]): Boolean = { | |
// Compute the paths from root to node for each element | |
def paths(arr: Array[Int]): Map[Int, String] = { | |
var map = Map.empty[Int, String] |
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 | |
-------------------------- | |
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 | |
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms | |
Read 4K randomly from SSD* 150,000 ns 0.15 ms |
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
/** | |
* Compute all BSTs with nodes with values from 1 to `n` | |
* | |
* @return Roots of BSTs | |
*/ | |
def allBSTs(n: Int): Seq[Node] = { | |
val memo = Array.ofDim[Seq[Node]](n + 1, n + 1) | |
def all(from: Int, to: Int): Seq[Node] = { | |
if (from > to) Seq(null) // Null child pointer |
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
def palindromePartitions(s: String): Seq[Seq[String]] = { | |
val n = s.length - 1 | |
def isPalindrome(i: Int, j: Int): Boolean = | |
i >= j || s.charAt(i) == s.charAt(j) && isPalindrome(i + 1, j - 1) | |
// Palindromes starting at s[i] | |
def partition(i: Int): Seq[Seq[String]] = | |
if (i == n + 1) Seq(Seq()) | |
else for { |
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
// https://www.hackerearth.com/submission/34845/ | |
#include <cstdio> | |
#include <algorithm> | |
#include <cstring> | |
#include <set> | |
#include <vector> | |
#include <queue> | |
#include <map> | |
#include <iostream> |
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
// https://www.hackerearth.com/submission/34813/ | |
import java.io.*; | |
import java.util.*; | |
import java.lang.Math.*; | |
class ques3 | |
{ | |
public static void main(String args[])throws Exception | |
{ |
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
// https://www.hackerearth.com/submission/1808199/ | |
/* IMPORTANT: class must not be public. */ | |
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.util.ArrayList; | |
import java.util.HashSet; | |
import java.util.List; | |
import java.util.Set; |
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
/** | |
* Minimum number of swaps to rearrange to adjacent pairs | |
* http://www.geeksforgeeks.org/minimum-number-of-swaps-required-for-arranging-pairs-adjacent-to-each-other/ | |
* | |
* @param arr Array of integers | |
* @param pairings Map of pairs | |
* @return Tuple of the minimum number of swaps and the rearrangements with minimal | |
* swaps such that each rearrangement is a list of adjacent pairs | |
*/ | |
def minSwapsForAdjacentPairs(arr: Array[Int], pairings: Map[Int, Int]): (Int, Seq[Seq[Int]]) = { |
OlderNewer