Leetcode 1688 in Scala
Briefly