Unique element B/W two LIST in SCALA
It is one of the most asked question in interview
and i have the easiest of answer by using methods magic in scala
SOLUTION ->
def main(args: Array[String]): Unit = {
val l1= List(1,2,3,4)
val l2= List(2,3,4,5)
val op = l1.diff(l2) ::: l2.diff(l1)
println(op)
}
expected output is List(1,5) as these are the only element that are unique in both the list
Comments
Post a Comment