fork download
  1. object Main extends App {
  2. val x : List[Int] = List(4,3,2,5,6,8,5,9,7)
  3. def getMinArray(remaining : List[Int], fwd : List[Int]) : List[Int] = {
  4. remaining match {
  5. case head::tail => {
  6. def sublistMin(l : List[Int], min: Int) : List[Int] =
  7. l match {
  8. case head::tail =>
  9. if (head > min) sublistMin(tail, min) else min::l
  10. }
  11. val fwdNext = sublistMin(fwd, head)
  12. fwdNext(1)::getMinArray(tail, fwdNext)
  13. }
  14. case Nil => List.empty[Int]
  15. }
  16. }
  17. print (getMinArray(x, List(-1)))
  18.  
  19. }
Success #stdin #stdout 0.38s 322176KB
stdin
Standard input is empty
stdout
List(-1, -1, -1, 2, 5, 6, 5, 5, 5)