Min Max Riddle

  • + 0 comments

    Solution in javascript, it passes all test cases but 1 and it fails because timeout so i'd say is almost okey, althought im not using stacks or queues:

    function riddle(arr) {
        // solve here
        let result = []
        let tempDict = new Map([[0, Number.MAX_SAFE_INTEGER]]);
        
        let minimum = 0;
        for(let i=0; i<arr.length; i++){
            let group= 1;
      
            for(let j=i; j<arr.length; j++){
                  
                let min=Math.min(tempDict.get(group-1), arr[j]);
                tempDict.set(group, min )
                result[group-1] = result[group-1]!= undefined? Math.max(result[group-1], min) : min
                group++;
            }
       
        }
        
        
        return result;
    }