Sort by

recency

|

715 Discussions

|

  • + 0 comments

    So this isn't dynamic programming at all unless dp = having to change the submission system for it to be valid...

  • + 0 comments

    Can anyone shed light on how to complete this problem in Cpp. The problem requires the function to return int while the ouput can exceed the bound of a 32-bit integer? Does this not make it fundamentally impossible to correctly implement a Cpp solution? Am I dumb (yes but thats beside the point)...?

  • + 0 comments

    this is my code in python, it exceeded the time with Python3 but passed with PyPy3

    def fibonacciModified(t1, t2, n):
        prev, prev2 = t2, t1
        
        for step in range(2,n):
            prev, prev2 = prev**2 + prev2, prev
    
        return prev
    
  • + 0 comments

    the number is too big

  • + 0 comments

    My solution Js, using memoization and closures.

    function fibonacciModified(t1, t2, n) {
        // Write your code here
        return memoized(t1, t2)(n);
    }
    
    const memoized = (t1, t2) => {
        const obj = { 1: BigInt(t1),
                      2: BigInt(t2) };
        return function fib(n) {
            if (obj[n]) {
                return obj[n]; 
            } else {
                if (n === 1) {
                    return BigInt(t1);
                } else if (n === 2) {
                    return BigInt(t2);
                } else {
                    obj[n] = BigInt(fib(n - 2)) + BigInt(fib(n - 1) ** BigInt(2));
                    return obj[n];
                }
            }
        } 
    # };