You are viewing a single comment's thread. Return to all comments →
O(n) solution (Scala):
def icecreamParlor(m: Int, arr: Array[Int]): Array[Int] = { val data = arr.toSeq.zip(1 until Int.MaxValue).groupBy(_._1).view.mapValues(_.map(_._2)).toMap data.keys.flatMap { a => val b = m - a data.get(b) match { case Some(positions) => if (a == b & positions.length >= 2) Some(Seq(positions(0), positions(1))) else if (b > a) Some(Seq(data(a)(0), positions(0)).sorted) else None case _ => None } }.head.toArray }
Seems like cookies are disabled on this browser, please enable them to open this website
Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
O(n) solution (Scala):