-
Notifications
You must be signed in to change notification settings - Fork 382
Closed
Labels
Description
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
Additional context
No response