Skip to content

Missing Test Case - 1642. Furthest Building You Can Reach #20434

@yxue95

Description

@yxue95

LeetCode Username

xyx76023

Problem number, title, and link

1642. Furthest Building You Can Reach

Category of the bug

  • Problem description
  • Solved examples
  • Problem constraints
  • Problem hints
  • Incorrect or missing "Related Topics"
  • Incorrect test Case (Output of test case is incorrect as per the problem statement)
  • Missing test Case (Incorrect/Inefficient Code getting accepted because of missing test cases)
  • Editorial
  • Programming language support

Description of the bug

My insufficient answer is accepted but shouldn't

Language used for code

Java

Code used for Submit/Run operation

class Solution {
    public int furthestBuilding(int[] heights, int bricks, int ladders) {

        PriorityQueue<Integer> pq = new PriorityQueue<>();
        
        for (int i = 0; i < heights.length - 1; i++) {
            int diff = heights[i + 1] - heights[i];

            if (diff <= 0) {
                continue;
            }

            if (ladders > 0) {
                pq.add(diff);
                ladders--;
            } else if (!pq.isEmpty() && pq.peek() < diff) {

                bricks -= pq.poll(); 
                pq.add(diff); 
                
                if (bricks < 0) {
                    return i;
                }
            } else {

                bricks -= diff;
                if(bricks == 0) {
                    return i+1;
                }
                if (bricks < 0) {
                    return i;
                }
            }
        }
        
        return heights.length - 1;
    }
}

Expected behavior

For test case: heights = [1,5,8,8], bricks = 3, ladders = 1, my solution yields wrong answer but gets AC when submitted.

Screenshots

sc1

sc2

Additional context

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions