<commit_before>package leetcode;

/**
 * https://leetcode.com/problems/furthest-building-you-can-reach/
 */
public class Problem1642 {
    public int furthestBuilding(int[] heights, int bricks, int ladders) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1642 prob = new Problem1642();
        System.out.println(prob.furthestBuilding(new int[]{4,2,7,6,9,14,12}, 5, 1)); // 4
        System.out.println(prob.furthestBuilding(new int[]{4,12,2,7,3,18,20,3,19}, 10, 2)); // 7
        System.out.println(prob.furthestBuilding(new int[]{14,3,19,3}, 17, 0)); // 3
    }
}<commit_msg>Solve problem 1642<commit_after>package leetcode;

import java.util.PriorityQueue;

/**
 * https://leetcode.com/problems/furthest-building-you-can-reach/
 */
public class Problem1642 {
    public int furthestBuilding(int[] heights, int bricks, int ladders) {
        PriorityQueue<Integer> pq = new PriorityQueue<>((a, b) -> Integer.compare(b, a));
        for (int i = 1; i < heights.length; i++) {
            int diff = heights[i] - heights[i - 1];
            if (diff > 0) {
                pq.add(diff);
                bricks -= diff;
                if (bricks < 0) {
                    ladders--;
                    bricks += pq.poll();
                    if (bricks < 0 || ladders < 0) {
                        return i - 1;
                    }
                }
            }
        }
        return heights.length - 1;
    }
}
{'fraction_non_alphanumeric': 0.14759647935003387, 'fraction_numerical': 0.046039268788083954, 'mean_word_length': 1.8588007736943908, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '1069363', 'n_tokens_mistral': 540, 'n_tokens_neox': 470, 'n_words': 101}