Skip to content

Instantly share code, notes, and snippets.

@royki
Forked from feliperazeek/CodilityPermCheck.scala
Created July 31, 2019 20:58
Show Gist options
  • Save royki/ce9234259b7f455e2b0850a0d963d8db to your computer and use it in GitHub Desktop.
Save royki/ce9234259b7f455e2b0850a0d963d8db to your computer and use it in GitHub Desktop.
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 =>
false
case (x, _) if x < 1 || x > 1000000000 =>
false
case (0, _) =>
false
case (_, true) =>
false
case _ =>
bitz.set(i)
true
}
} else false
)
if (good && A.size > 0 && A.size <= 100000) 1
else 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment