Skip to content

Missing Test Case - 904. Fruit Into Baskets #6512

@ya7ya1994

Description

@ya7ya1994

Your LeetCode username

ya7ya1994

Category of the bug

  • Question
  • Solution
  • Language
  • Missing Test Cases

Description of the bug

This brute force solution passes because of a missing test case
[0,...<40k zeros>,1,2,3]

Code you used for Submit/Run operation

class Solution {
    public int totalFruit(int[] fruits) {
        int maxFruits = 0;
        for (int i = 0; i < fruits.length && maxFruits < fruits.length; i++) {
            maxFruits = Math.max(maxFruits,computeAll(fruits,i));
        }
        
        return maxFruits;
    }
    public int computeAll(int[] fruits, int beg) {
        Map<Integer,Integer> basket = new HashMap();
        int result = 0;
        for(int i = beg; i < fruits.length; i++) {
            if(!basket.containsKey(fruits[i])) {
                if (basket.size() < 2) {
                    basket.put(fruits[i],1);
                }
                else {
                    break;
                }
            }
            else {
                basket.put(fruits[i],basket.get(fruits[i]) + 1);
            }
        }
        
        for(int i : basket.values())
            result += i;
        
        return result;

    }
}

Language used for code

Java

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions