Leetcode 945. Minimum Increment to Make Array Unique

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ธ.ค. 2024

ความคิดเห็น • 6

  • @middleagedprogrammer-hl6oz
    @middleagedprogrammer-hl6oz ปีที่แล้ว +1

    Really good explanation!

  • @karthiklv29
    @karthiklv29 ปีที่แล้ว +1

    amazing explanation

  • @DK-ox7ze
    @DK-ox7ze ปีที่แล้ว +1

    In line 12 of your code, how's it guaranteed that newValue will be at max only one less than nums[i-1]?

    • @luvgohel4602
      @luvgohel4602 5 หลายเดือนก่อน

      Becuz we have sorted array & increment nums(i-1) value that's why nums(i-1) is greater than or equal current nums(I) value 😊

  • @priyanshkumar17
    @priyanshkumar17 5 หลายเดือนก่อน

    Initially, I thought of using Next Greater to Left & Next Greater to Right concepts, & did dry run as per below written code for the test cases, [1,2,2], [3,2,1,2,1,7] & [4,4,4,4,4]. According to the dry run, I got the correct answers, but when I run the test cases on leetcode, I get correct output for [1,2,2], but for [3,2,1,2,1,7] & [4,4,4,4,4], it shows output of 4, which is wrong. My dry run (as per the same code) yielded correct answer, but on running on platform, it fails. Can anyone help me address this issue ? The code is :
    class Solution {
    private:
    vector NGR(vector& arr, int n){
    stack st;
    vector result(n, -1);
    for (int i = n - 1; i >= 0; i--) {
    while (!st.empty() && st.top()

  • @SIMAR_SINGH_RAYAT
    @SIMAR_SINGH_RAYAT 5 หลายเดือนก่อน +2

    Wrong solution