All paths solution : judge results for two different test cases identical! what am I missing?


  • 0
    R
    class Solution {
        int count_to_target(int index, vector<int>& nums) {
            
            if(index == nums.size() - 1 || index >= nums.size()) {            
                return 0;    
            }
                    
            //
            // always two possibilities avaialble at any index
            // either take the jump or move one step to the right
            //
            
            int jump_taken = 0;                
            if(nums[index] > 0) {
                jump_taken = count_to_target(index + nums[index], nums);
            }        
            
            int moved_right = count_to_target(index + 1, nums);
            
            return (min(jump_taken, moved_right) + 1);        
        }
        
    public:
        int jump(vector<int>& nums) {
           return count_to_target(0, nums);        
        }
    };
    

    Judge Results interesting:

    For this sequence, [4,1,1,1,3,1,1] , judge returns the no of steps = 2
    and for [4,1,1,3,1,1,1], judge returns no of steps = 2

    What am I missing?


Log in to reply
 

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