Skip to content

Instantly share code, notes, and snippets.

View feliperazeek's full-sized avatar
💭
Be there and give a shit

Felipe Oliveira feliperazeek

💭
Be there and give a shit
View GitHub Profile
@feliperazeek
feliperazeek / CodilityTreeHeight.scala
Created October 7, 2015 06:54
Codility TreeHeight Scala
object Solution {
def solution(T: Tree): Int = {
def height(t: Tree, i: Int): Int = {
val left = (Option(t.l).map(height(_, i + 1)) getOrElse i)
val right = (Option(t.r).map(height(_, i + 1)) getOrElse i)
scala.math.max(i, scala.math.max(left, right))
}
@feliperazeek
feliperazeek / CodilityOddOccurrencesInArray.scala
Last active July 31, 2019 20:57
Codility OddOccurrencesInArray
object Solution {
def solution(A: Array[Int]): Int = {
val N = A.size
if (N < 1 || N > 1000000) sys.error(s"Invalid array size: $N")
A.foldLeft(0) { (current, i) =>
i ^ current
}
}
@feliperazeek
feliperazeek / CodilityCountFactors.scala
Created September 28, 2015 05:31
Codility CountFactors
object Solution {
def solution(N: Int): Int = {
if (N < 1) sys.error(s"Invalid input: $N")
@scala.annotation.tailrec
def foo(i: Int, total: Int): (Int, Int) = {
if ((i * i) >= N) (total, i)
else if (N % i == 0) foo(i + 1, total + 2)
else foo(i + 1, total)
}
@feliperazeek
feliperazeek / CodilityMissingInteger.scala
Created September 17, 2015 06:30
Codility Missing Integer in Scala
object Solution {
def solution(A: Array[Int]): Int = {
val bitz = new java.util.BitSet(A.size)
val n = A.foldLeft(0) { (total, i) =>
if (i > 0 && i <= A.size && !bitz.get(i)) {
bitz.set(i)
total + 1
} else total
import scala.math.{min, abs}
object Solution {
def solution(A: Array[Int]): Int = {
if (A.size < 2 || A.size > 100000) sys.error(s"Invalid input - array size: ${A.size}")
val total = A.map(_.toLong).sum
(A.foldLeft[(Int, Long, Long)](-1, -1, 0l) { (t, i) =>
if (i < -1000 || i > 1000) sys.error(s"Invalid array element: $i")
object Solution {
def solution(A: Array[Int]): Int = {
(A.foldLeft[(Int, Option[Double], Int)]((0, None, -1)) { (t, item) =>
val (index, min, results) = t
val checkPair = index <= A.size - 2
val checkTrio = index <= A.size - 3
object Solution {
def solution(A: Array[Int]): Int = {
val (results, _) = A.sorted.foldLeft((0, 0)) { (t, item) =>
val (current, last) = t
val next = last + 1
item match {
case x if x < 0 => (current, last)
case `last` => (item, item)
object Solution {
def solution(A: Array[Int]): Int = {
val positive = new java.util.BitSet()
val negative = new java.util.BitSet()
A.foldLeft(0) { (current, i) =>
val duplicate = if (i < 0) (negative get i * -1)
else (positive get i)
duplicate match {
import java.util.BitSet
object Solution {
def solution(A: Array[Int]): Int = {
val bitz = new BitSet(A.size + 1)
val good = A.foldLeft(true)((current, i) =>
if (current) {
(i, bitz.get(i)) match {
case (x, _) if x > A.size =>
@feliperazeek
feliperazeek / hive-site.xml
Created July 3, 2014 17:24
Hortonworks suggested settings Tez/Hive
<property>
<name>hive.vectorized.groupby.flush.percent</name>
<value>0.1</value>
</property>
<property>
<name>hive.vectorized.groupby.maxentries</name>
<value>10240</value>
</property>
<property>
<name>tez.session.am.dag.submit.timeout.secs</name>