Skip to content

Missing Test Case - 3326. Minimum Division Operations to Make Array Non Decreasing #24876

@safi-wasif

Description

@safi-wasif

LeetCode Username

safi_jsr

Problem Number, Title, and Link

https://leetcode.com/problems/minimum-division-operations-to-make-array-non-decreasing/description/

Bug Category

Missing test case (Incorrect/Inefficient Code getting accepted because of missing test cases)

Bug Description

The output that this code produces is 2 for the test case [8,6,8] while the correct answer should be 1. However, this solution is accepted. Please rectify this error.

Language Used for Code

C++

Code used for Submit/Run operation

class Solution {
public:
    int prime(int n){
        for(int i=2;i*i<=n;i++){
            if(n%i==0)return 0;
        }
        return 1;
    }

    int minOperations(vector<int>& nums) {
        int n=nums.size(),count=0;
        if(is_sorted(nums.begin(),nums.end()))return 0;
        for(int i=n-2;i>=0;i--){
            if(!prime(nums[i])){
                
                    for(int j=2;j<=nums[i];j++){
                        if(nums[i]%j==0){
                            nums[i]=j;
                            break;
                        }
                    }
                ++count;
            }
            if(nums[i]>nums[i+1])return -1;
        }    
        return count;
    }
};

Expected behavior

The output that this code produces is 2 for the test case [8,6,8] while the correct answer should be 1. However, this solution is accepted. Please rectify this error.

Screenshots

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions