Custom test for a failed Submission input succeeds


  • 0
    C
     * Definition for a binary tree node.
     * function TreeNode(val) {
     *     this.val = val;
     *     this.left = this.right = null;
     * }
     */
    /**
     * @param {TreeNode} root
     * @return {number}
     */
    const values = {
    	'l_biggest': 0,
    	'r_biggest': 0,
    	'lastHash': 0,
    };
    
    var maxPathSum = function(root) {
    	let hash_key = 0;
    
        values[hash_key] = 0;
    
    	parseNode(root);
    
    	return root.val + values.l_biggest + values.r_biggest;
    };
    
    function parseNode(node, type) {
    	const left = node.left;
    	const right = node.right;
    	const l_val = (left && left.val) || 0;
    	const r_val = (right && right.val) || 0;
    	const last_value = values[values.lastHash];
    	const biggest = values[`${type}_biggest`];
    
    	if (last_value > biggest) {
    		values[`${type}_biggest`] = last_value
    	}
    
    	if (left) {
    		values.lastHash += 1;
    		values[values.lastHash] = last_value + l_val;
    		parseNode(left, type || 'l');
    	}
    
    	if (right) {
    		values.lastHash += 1;
    		values[values.lastHash] = last_value + r_val;
    		parseNode(right, type || 'r');
    	}
    }
    

    this code in javascript fails for the submissions test of an [0] array
    and succeeds for a custom test of [0]

    any reason behind this unexpected behaviour?


Log in to reply
 

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