We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Missing Numbers (FP)
Missing Numbers (FP)
+ 0 comments F#
stdin.ReadLine() let A = stdin.ReadLine().Split()|> Array.countBy id stdin.ReadLine() stdin.ReadLine().Split()|> Array.countBy id |> Array.except A |> Array.map fst |> Array.sort |> String.concat " " |> printfn "%s"
+ 0 comments f# solution
open System let getCount key s = match Seq.tryFind (fun (k, _) -> k = key) s with | Some(_, values) -> Seq.length values | None -> 0 let _ = Console.ReadLine() let left = Console.ReadLine() |> (fun s -> s.Split(" ")) let _ = Console.ReadLine() let right = Console.ReadLine() |> (fun s -> s.Split(" ")) let groupLeft = left |> Seq.groupBy id let groupRight = right |> Seq.groupBy id Seq.append left right |> Seq.distinct |> Seq.filter (fun key -> (getCount key groupLeft) <> getCount key groupRight) |> List.ofSeq |> Seq.sort |> String.concat " " |> Console.WriteLine
+ 0 comments haskell
import Data.List (intercalate) import Data.Array (accumArray, elems) counts l u xs = accumArray (+) 0 (l, u) [(x, 1) | x <- xs] missing l u xs ys = let cx = elems $ counts l u xs cy = elems $ counts l u ys in [i | (i, a, b) <- zip3 [l..] cx cy, a < b] main = do getLine lx <- getLine getLine ly <- getLine let xs = map read $ words lx :: [Int] ys = map read $ words ly :: [Int] l = min (minimum xs) (minimum ys) u = max (maximum xs) (maximum ys) putStrLn $ intercalate " " $ map show $ missing l u xs ys
+ 0 comments Scala:
object Solution { import scala.io.StdIn.{readInt, readLine} def main(args: Array[String]): Unit = { val A = readList val B = readList println(missingVals(A, B).sorted.mkString(" ")) } def readList: List[Int] = { val _ = readInt readLine.split(' ').map(_.toInt).toList } def missingVals[T](A: List[T], B: List[T]): List[T] = { val (mapA, mapB) = (countMap(A), countMap(B)) (mapA.keySet | mapB.keySet) .filterNot(n => mapA(n) == mapB(n)) .toList } def countMap[T](l: List[T]): Map[T, Int] = { val m = Map.empty[T, Int].withDefaultValue(0) l.foldLeft(m)((m, e) => m + (e -> (m(e) + 1))) } }
+ 0 comments This is to assist anyone who gets a 4096 limit on stdio. I had this limit testing Elixir using VS. It was due to copy paste. I then tested the long inputs directly at the hackerrank site.
Hence my conclusion is to use the site for the long stdio inputs due to copy paste limitations.
Load more conversations
Sort 19 Discussions, By:
Please Login in order to post a comment