• + 1 comment

    KOTLIN

    Only one Test passed, can someone help with a good explainatory sudo code solution to this problem?

    my code though

    fun solve(f: Array<Int>): Int {
            var stack = mutableListOf<Int>()
            fun fibonacci(b : Int) : Int{
                return if(b == 0) 0 else if(b == 1) 1
                else fibonacci(b - 1) + fibonacci(b -2)
            }
            fun gcd (a : Int,b: Int) : Int{
                if(a==0) return b else return gcd(b%a,a)
            }
    
            fun lcm(a:Int,b:Int):Int{
                return (a*b)/gcd(a,b)
            }
            f.forEach{
                stack.add(fibonacci(it))
            }
            var lcmResult =  stack[0]
    
            for(i in 1 until stack.size){
                lcmResult = lcm(lcmResult,stack[i])
            }
    
     
    
            return lcmResult
        }