I have a List and Map as below,
val exampleList = List("A","B","C","D","E","A","L","M","N")
val exampleMap = Map("W1" -> Vector(4,8),
"W2" -> Vector(5),
"W3" -> Vector(9))
So I need to add all the letters in the exampleMap to the exampleList according to the values (indexes that should take places in the exampleList) that in the exampleMap. So the final output should be something like this
val result = List("A","B","C","D","W1","E","W2","A","L","M","W1","N","W3")
I tried several ways using foldLeft as well as using flatMap but still not get any luck.
I am making two assumptions
To solve, I would first change exampleMap as follows,
and then use it to create the final list.