Skip to content

Missing Test Case - 2366. Minimum Replacements to Sort the Array #31631

@Santoshpawa

Description

@Santoshpawa

LeetCode Username

singhpawarsantosh

Problem Number, Title, and Link

2366, Minimum Replacements to Sort the Array, https://leetcode.com/problems/minimum-replacements-to-sort-the-array/

Bug Category

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

Bug Description

This is a test case created by me : [ 1 , 2 , 10 , 3 ]
The correct answer is : 4
But the code which I wrote is giving answer : 3
And this wrong answer is accepted by the compiler, without giving any error.

Language Used for Code

JavaScript

Code used for Submit/Run operation

/**
 * @param {number[]} nums
 * @return {number}
 */
var minimumReplacement = function(nums) {
    let operations =0;
    let n = nums.length;
    let parts = null;
    for(let i = n-2 ; i>=0; --i){
        if(nums[i]<=nums[i+1]){
            continue;
        }
        parts = Math.floor(nums[i]/nums[i+1]);
        if(nums[i]% nums[i+1] !== 0){
            ++parts;
        }
        operations += (parts-1);
        nums[i] = Math.floor(nums[i]/parts);
    }
    return operations;
};

Expected behavior

This is a test case created by me : [ 1 , 2 , 10 , 3 ]
The correct answer is : 4
But the code which I wrote is giving answer : 3
And this wrong answer is accepted by the compiler, without giving any error.

Screenshots

Image

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions