Leetcode Weekly Contest 412 | Video Solutions - A to D | by Viraj Chandra | TLE Eliminators

Поделиться
HTML-код
  • Опубликовано: 9 ноя 2024

Комментарии • 27

  • @TLE_Eliminators
    @TLE_Eliminators  2 месяца назад +3

    Please fill the Feedback form for PCD: forms.gle/tKfrRNnejeuZfUSt8

  • @Sunil-cc1ei
    @Sunil-cc1ei 2 месяца назад +10

    Best tutor at tle.

  • @shreyanshjain1595
    @shreyanshjain1595 2 месяца назад +3

    VERY GOOD EXPLANATION OF ALL THE FOUR PROBLEMS

  • @YashwanthsaiCh
    @YashwanthsaiCh 2 месяца назад +21

    bhai tu hi CF and CC contests ka videos bana...bahut acccha seekhatha hai :)

    • @VirajChandra
      @VirajChandra 2 месяца назад +10

      Thankyou bhai!

    • @arl0817osho
      @arl0817osho 2 месяца назад +2

      @@VirajChandra sch m esa lgta h ki kitna easy tha question jb smjhate ho bhaiya aap

  • @haryannvi-coder
    @haryannvi-coder 2 месяца назад +2

    good explanation viraj 👏👏

  • @saimaripala-0638
    @saimaripala-0638 2 месяца назад +3

    3 explanation was 🔥

  • @akashsonar6332
    @akashsonar6332 2 месяца назад +1

    Whew! I wounder how he made it to the observation.

  • @rajchinagundi7498
    @rajchinagundi7498 2 месяца назад +3

    I feel brute force for question 2 could have been done in a simpler way, reducing its space complexity
    ```
    class Solution {
    public:
    bool swapCheck(int a,int b){
    string x=to_string(a);
    string y=to_string(b);
    int count=0;
    for(int i=0;i

  • @coder_07
    @coder_07 2 месяца назад +3

    Thanks @VraijChandra

  • @Jv_Singh37
    @Jv_Singh37 2 месяца назад +1

    good explanation of time complexity

  • @rajchinagundi7498
    @rajchinagundi7498 2 месяца назад +1

    How is the initial state achieved?
    (1LL*multiplier*pq.top().first)%mod)

    • @priyanshuthapliyal104
      @priyanshuthapliyal104 2 месяца назад +2

      ### **Initial Setup:**
      - **Array:** `[2, 1, 3, 5, 6]`
      - **k:** `5`
      - **multiplier:** `4`
      - **mod:** `1e9 + 7`
      - **n:** `5` (size of the array)
      ### **Step 1: Calculate Maximum Element**
      - **Maximum element (`maxi`):** `6`
      ### **Step 2: Build Initial Priority Queue**
      We create a min-heap using a priority queue:
      - After inserting all elements, the priority queue looks like this (based on the min-heap property):
      ```
      pq: [(1, 1), (2, 0), (3, 2), (5, 3), (6, 4)]
      ```
      ### **Step 3: Process the Queue for `k` Operations**
      We start multiplying the minimum element until the condition `(1LL * multiplier * pq.top().first) 6`
      - The condition fails, so the loop terminates immediately. **`k` remains `4`** because the loop didn't perform any operation.
      ### **Step 4: Calculate Power**
      - **Calculate Power:** `pow = modPower(4, k/n) = modPower(4, 4/5)`.
      - **pow = modPower(4, 0) = 1** (integer division `4/5` gives `0`).
      ### **Step 5: Apply Remaining Multiplications**
      The remainder of `k` (i.e., `k % n = 4 % 5 = 4`) means we multiply the next `4` elements by `4` directly.
      - **Remaining `k = 4`, so we multiply the smallest `4` elements:**
      - **1st Pop:**
      - **Value:** `2` at index `0`.
      - **Result:** `nums[0] = 2 * 4 = 8`
      - **Priority Queue:**
      ```
      pq: [(3, 2), (4, 1), (5, 3), (6, 4)]
      ```
      - **2nd Pop:**
      - **Value:** `3` at index `2`.
      - **Result:** `nums[2] = 3 * 4 = 12`
      - **Priority Queue:**
      ```
      pq: [(4, 1), (6, 4), (5, 3)]
      ```
      - **3rd Pop:**
      - **Value:** `4` at index `1`.
      - **Result:** `nums[1] = 4 * 4 = 16`
      - **Priority Queue:**
      ```
      pq: [(5, 3), (6, 4)]
      ```
      - **4th Pop:**
      - **Value:** `5` at index `3`.
      - **Result:** `nums[3] = 5 * 4 = 20`
      - **Priority Queue:**
      ```
      pq: [(6, 4)]
      ```
      ### **Step 6: Final Array Construction**
      Now, only one element (`6`) remains unmodified.
      - **Final State of the Array:**
      ```
      nums = [8, 16, 12, 20, 6]
      ```
      ### **Summary:**
      - **Initial k:** `5`
      - **k after the first loop:** `4`
      - **Second iteration condition fails, so `k` remains `4`.**
      The final array is `[8, 16, 12, 20, 6]`. The approach correctly handles the scenario where no further operations can be performed, ensuring that `k` is only reduced when an operation is actually executed.

    • @rajchinagundi7498
      @rajchinagundi7498 2 месяца назад

      @@priyanshuthapliyal104 your second iteration, does not satisfy his initial state statment, where the multiplier is said to multiply all the elements atleast once

    • @apputadhiyal9451
      @apputadhiyal9451 2 месяца назад

      @@rajchinagundi7498 Did you find out why is it working?

    • @apputadhiyal9451
      @apputadhiyal9451 2 месяца назад

      Actually the multiplication becomes circular after as soon as min*multiplier exceeds mx, not necessarily until each element is multiplied at least once! Eg=>
      assume multiplier = 2
      0 [1, 2, 3] (initially array)
      1 [2, 2, 3]
      2 [4,2,3]
      3 [4, 4, 3]
      4 [4, 4, 6]
      5 [8, 4, 6]
      6 [8, 8, 6]
      7 [8, 8, 12]
      ...
      notice after 1 where min in array is 2, 2*2 > 3 so we came out of the first loop .
      now see that [k=4] is 2*[k=1]
      and [k=7] is 2*[k =4]
      this will continue
      so the multiplication became circular from k=1 itself not from 4.
      hence the condition pq.top().first * multiplier

    • @47_prashantkumar54
      @47_prashantkumar54 2 месяца назад +1

      @@rajchinagundi7498 yes having the same doubt ,the pq will break prior before each place multiplied atleast 1,
      and if we write conditon pq.top().second

  • @Blackhawk_9
    @Blackhawk_9 2 месяца назад +1

    Sir, in the code from line 28-34 how are we ensuring that we are multiplying the element which has least index among all the similar numbers(if there are) ?

    • @VirajChandra
      @VirajChandra 2 месяца назад

      Since priority queue is made from a pair, second index is also maintained.

  • @ITSuyashTiwari
    @ITSuyashTiwari 2 месяца назад +2

    got 3rd problem very clearly

  • @adityacr7407
    @adityacr7407 2 месяца назад +3

    In B , we can simplify the process :
    CHECK THIS OUT
    class Solution {
    public:
    bool swapit(int i, int j, vector &nums) {
    string str1 = to_string(nums[i]);
    string str2 = to_string(nums[j]);

    while(str1.size()>str2.size())
    str2 = '0' + str2;

    while(str1.size()