Why does this solution get MLE?


  • 0

    Hi! Why does this solutions get Memory Limit Exceeded error? Submission page says that 57/57 test cases passed and last executed input was [].

    /**
     * @param {number[]} nums
     * @return {number[][]}
     */
    var findSubsequences = function(nums) {
    
        if (nums.length === 0)
            return [];
    
        const res = [];
        const DP = Array(nums.length).fill(0).map(v => []);
        for (let i = 0; i < nums.length; i++) {
            if (nums.indexOf(nums[i]) === i)
                DP[i].push([nums[i]]);
        }
    
        for (let i = 0; i < nums.length; i++) {
            for (let j = i - 1; j >= 0; j--) {
                if (nums[j] > nums[i])
                    continue;
                for (let k = 0; k < DP[j].length; k++) {
                    const seq = DP[j][k];
                    const newseq = seq.concat(nums[i]);
                    DP[i].push(newseq);
                    res.push(newseq);
                }
                if (nums[j] === nums[i])
                    break;
            }
        }
    
        return res;
    };
    

  • 2

    Hi @dettier,

    Sorry for the trouble, we'll look into this, and tell you our feedback as soon as possible.

    Best,
    Leetcode Team


  • 3

    @dettier Hi, we've verified that your solution actually should passes the judge with a little of memory limit increase. The memory was a little tight for JS. We've increased the memory limit slightly, and will start to rejudge all JS solution for this problem now. Thanks for your patience.


  • 0

    @1337c0d3r Thanks!


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.