This file contains hidden or 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
public static int partitionKDim(int[] A, int k, int target) { | |
int[][][] mem = new int[k + 1][A.length + 1][target + 1]; | |
for (int t = 0; t < k + 1; t++) { | |
for (int i = 0; i < A.length + 1; i++) { | |
mem[t][i][0] = 1; | |
} | |
} |
This file contains hidden or 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
[ | |
{ | |
"action": "talk", | |
"text": "Please wait while we connect you." | |
} | |
] |
This file contains hidden or 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
[ | |
{ | |
"action": "talk", | |
"text": "This is Jose, please wait while we connect you." | |
}, | |
{ | |
"action": "connect", | |
"timeout": 60, | |
"from": "12028525606", | |
"endpoint": [ |
This file contains hidden or 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 scala.annotation.tailrec | |
case class Pos(x: Int, y: Int) | |
object Queen { | |
def isSafe(a: Pos, b: Pos): Boolean = { | |
a.x != b.x && a.y != b.y && Math.abs(a.x - b.x) != Math.abs(a.y - b.y) | |
} | |
def isSafe(a: Pos, queens: List[Pos]): Boolean = queens match { |
This file contains hidden or 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
// ======================= | |
// Arrays: Left Rotation | |
// ======================= | |
def leftShift(input: Array[Int], rotations: Int): Unit = { | |
val tmpArray = new Array[Int](total) | |
val total = input.length | |
val pos = total - math.abs(rotations % total) |
This file contains hidden or 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
// combinations without repetition | |
// | |
// | |
// n! | |
// ---------- | |
// r!(n - r)! | |
// | |
// n = number of elements to choose from | |
// r = how many we choose | |
// |
This file contains hidden or 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
object Solution extends App { | |
// Scala | |
val image = Array( | |
Array(1, 1, 1, 1, 1, 1, 1), | |
Array(1, 1, 1, 1, 1, 1, 1), | |
Array(1, 1, 1, 0, 0, 0, 1), | |
Array(1, 1, 1, 0, 0, 0, 1), | |
Array(1, 1, 1, 0, 0, 0, 1), | |
Array(1, 1, 1, 1, 1, 1, 1) |
This file contains hidden or 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 tMap[T](tail: List[T], f: T => T): List[T] = { | |
@tailrec | |
def _q(tail: List[T], acc: List[T] = List()): List[T] = { | |
tail match { | |
case Nil => rev(acc) | |
case x :: xs => { | |
_q(xs, f(x) :: acc) | |
} | |
} |
This file contains hidden or 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 permutator[T](list: List[T]): List[List[T]] = { | |
def _p(total: Int, list: List[T]): List[List[T]] = { | |
if (total == 0) { | |
list.map(List(_)) | |
} else { | |
for (i <- list; | |
j <- _p(total - 1, list)) | |
yield { i :: j } | |
} |
This file contains hidden or 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
object EnumFormat { | |
implicit def jsonReads[A](enum: Enumeration): Reads[A] = new Reads[A] { | |
def reads(json: JsValue): JsResult[A] = json match { | |
case JsString(s) => { | |
try { | |
JsSuccess(enum.withName(s).asInstanceOf[A]) | |
} catch { | |
case _: NoSuchElementException => | |
JsError(s"Enumeration expected of type: '${enum.getClass}', but it does not contain '$s'") | |
} |