• + 2 comments

    Scala does tail recursion optimisation at compile-time and the recursive function is transformed into a loop by the compiler I was wondering why the following solution says "Run Time Error"

    @tailrec
    def mingle(p : String, q : String, acc : String = "" ) : String = {
    if(p.isEmpty) acc
    else  mingle(p.tail,q.tail,acc+p.head+q.head)
    

    }

    Is it because of same reason ?