<commit_before>/**
 * Given an array of non-negative integers, you are initially positioned at the
 * first index of the array.
 * 
 * Each element in the array represents your maximum jump length at that
 * position.
 * 
 * Your goal is to reach the furthestCurrStep index in the minimum number of jumps.
 * 
 * For example:
 * Given array A = [2,3,1,1,4]
 * 
 * The minimum number of jumps to reach the furthestCurrStep index is 2. (Jump 1 step from
 * index 0 to 1, then 3 steps to the furthestCurrStep index.)
 * 
 * Tags: Array, Greedy, DP
 */
class JumpGame2 {
    public static void main(String[] args) {
        
    }
    
    /**
     * Use furthestCurrStep to store how far we already can reach
     * Compare i with furthestCurrStep
     * If we run out of it, update and add 1 more step to result
     * Return if furthestCurrStep is already bigger than or equal to the length
     * Use furthestNextStep to store how far we can reach for the next step
     */
    public int jump(int[] A) {
        int step = 0;
        int furthestCurrStep = 0; // how far we already can reach
        int furthestNextStep = A[0]; // how far can we reach for next step
        
        for (int i = 1; i < A.length; i++) {
            if (i > furthestCurrStep) { // run out of we can reach, need one more step
                if(furthestNextStep > furthestCurrStep){
                    step++;
                    furthestCurrStep = furthestNextStep;
                    if (furthestCurrStep >= A.length - 1) return step;
                }
                else return -1; //cannot reach i
            }
            furthestNextStep = Math.max(furthestNextStep, i + A[i]);
        }
        return step;
    }
}
<commit_msg>Revert "update code."<commit_after>/**
 * Given an array of non-negative integers, you are initially positioned at the
 * first index of the array.
 * 
 * Each element in the array represents your maximum jump length at that
 * position.
 * 
 * Your goal is to reach the furthestCurrStep index in the minimum number of jumps.
 * 
 * For example:
 * Given array A = [2,3,1,1,4]
 * 
 * The minimum number of jumps to reach the furthestCurrStep index is 2. (Jump 1 step from
 * index 0 to 1, then 3 steps to the furthestCurrStep index.)
 * 
 * Tags: Array, Greedy, DP
 */
class JumpGame2 {
    public static void main(String[] args) {
        
    }
    
    /**
     * Use furthestCurrStep to store how far we already can reach
     * Compare i with furthestCurrStep
     * If we run out of it, update and add 1 more step to result
     * Return if furthestCurrStep is already bigger than or equal to the length
     * Use furthestNextStep to store how far we can reach for the next step
     */
    public int jump(int[] A) {
        int step = 0;
        int furthestCurrStep = 0; // how far we already can reach
        int furthestNextStep = A[0]; // how far can we reach for next step
        
        for (int i = 1; i < A.length; i++) {
            if (i > furthestCurrStep) { // run out of we can reach, need one more step
                if(furthestNextStep > furthestCurrStep){
                    step++;
                    furthestCurrStep = furthestNextStep;
                    if (furthestCurrStep >= A.length) return step;
                }
                else return -1; //cannot reach i
            }
            furthestNextStep = Math.max(furthestNextStep, i + A[i]);
        }
        return step;
    }
}

{'fraction_non_alphanumeric': 0.07652173913043478, 'fraction_numerical': 0.010144927536231883, 'mean_word_length': 2.0192475940507437, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2597605', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1004, 'n_words': 427}