Minimum Lights To Activate

Sdílet
Vložit
  • čas přidán 10. 07. 2024

Komentáře • 54

  • @hey.............
    @hey............. Před 2 lety +6

    public class Solution {
    public int solve(int[] A, int B) {
    int n = A.length;
    int i = 0;
    int count = 0;
    while(i < n) {
    boolean isBulbLighted = false;
    int lr = Math.max(i - B + 1, 0);
    int rr = Math.min(i + B - 1, n - 1);
    // 0, 0, 1, 0, 1, 0, 0, 1
    for(int j = rr; j >= lr; j--) {
    if(A[j] == 1) {
    count++;
    i = j;
    i += B;
    isBulbLighted = true;
    break;
    }
    }

    if(!isBulbLighted) {
    return -1;
    }
    }
    return count;
    }
    }

  • @niharikathakur4925
    @niharikathakur4925 Před 2 lety +8

    Bro, at first I was reluctant to watch a 19 minute video but the way you deliver the solution is absolute delight. The flow of the code and the explanation were in sync.

  • @bhaveshkumar6842
    @bhaveshkumar6842 Před 2 lety +6

    This is the best explanation for this question. Great job!

  • @mrinalmadhav8119
    @mrinalmadhav8119 Před 2 lety +4

    Mam plz aap continue rakhiye ye series, views ko dhyan mat dijiye
    Aapke channel bhut precious h
    Heere ho har koi tarash nhi sakta

  • @JagdeepSingh-cd4jk
    @JagdeepSingh-cd4jk Před 2 lety +7

    though the video was bit long , but it was worth watching it!! so nicely explained every bit of the line of code

  • @ANANDJULU
    @ANANDJULU Před 2 lety +2

    Very nicely explained, thank you!

  • @swatishambhavi3649
    @swatishambhavi3649 Před 2 lety

    Great explanation, thanks so much!

  • @payalpanjwani5332
    @payalpanjwani5332 Před rokem

    Good explanation! Thanks for helping out 🤗

  • @raj_kundalia
    @raj_kundalia Před 2 lety

    Thanks for the video!

  • @rohankumarshah5679
    @rohankumarshah5679 Před 2 lety +1

    quality of Explanation justifies your hard work !!

  • @dheerajkumarmeena629
    @dheerajkumarmeena629 Před rokem

    Nicely explained. Very easy to understand

  • @snake_case07
    @snake_case07 Před 2 lety

    Thanks for the explanation 😊

  • @masternik6126
    @masternik6126 Před 2 lety +1

    int Solution::solve(vector &A, int B) {

    int n = A.size();
    int count = 0;
    int i = 0;
    bool bulbfound = false;
    while(i=l){
    if(A[r]==1){
    count++;
    i = B+r;
    bulbfound = true;
    break;
    }
    r--;
    }
    if(!bulbfound) return -1;

    bulbfound = false;
    }
    return count;
    }

  • @user-nh1ol8zz7w
    @user-nh1ol8zz7w Před rokem

    Great Explanation
    Thanks :)

  • @ajaywadhwa3398
    @ajaywadhwa3398 Před rokem

    Wow !!!!! Really a good explanations.

  • @forlaliga7123
    @forlaliga7123 Před 2 lety

    Great explanation

  • @aditikatiyar5933
    @aditikatiyar5933 Před 2 lety

    solving this question looks a piece of cake when explained by her!!!

  • @mdshoiebiqbal6155
    @mdshoiebiqbal6155 Před 2 lety

    Thank you ,that was nice application

  • @nehanjalimanchikanti3974

    Most underrated channel

  • @VaibhavSingh-vy6gy
    @VaibhavSingh-vy6gy Před 2 lety

    Very nicely explained...Thanks

  • @rudragaming5281
    @rudragaming5281 Před 2 lety

    MOST AWSOME CONTENT MAAM...

  • @chiragkarnwal6740
    @chiragkarnwal6740 Před rokem

    Great Explanation❤

  • @ferozahmadqureshi8071
    @ferozahmadqureshi8071 Před 2 lety +2

    everytime I am stuck, you come up like magic. Thanks ma'm.

    • @shimlamam6066
      @shimlamam6066 Před 2 lety +1

      R u wall clock alwys stuck after putting battary u charged

  • @dhruvpurwar6642
    @dhruvpurwar6642 Před 2 lety

    Fantastic explanation!! KUDOS

  • @keya.bitspilani5429
    @keya.bitspilani5429 Před rokem

    Intuitive solution❤

  • @tanzeelahmed2055
    @tanzeelahmed2055 Před 2 lety +3

    What an awesome explanation!

  • @surajsingh-sm7qx
    @surajsingh-sm7qx Před rokem

    Nice explaination 😊

  • @anikethdeshpande8336
    @anikethdeshpande8336 Před rokem

    nicely explained. !

  • @devanshsharma2106
    @devanshsharma2106 Před 2 lety

    such a good video

  • @jatinbhatoya8420
    @jatinbhatoya8420 Před 2 lety

    for java folks:
    public static int solve(int[] arr, int k) {
    if (k==0) return -1;
    int i = 0, count = 0;
    while (i < arr.length) {
    int idx = lightItUp(arr, k, i);
    if (idx == -1) return -1;
    else {
    i = idx + k;
    count++;
    }
    }
    return count;
    }
    public static int lightItUp(int arr[], int k, int i) {
    int j = Math.min(i + k - 1, arr.length - 1);
    while (j >= Math.max(i - k + 1, 0)) {
    if (arr[j] == 1) {
    return j;
    }
    j--;
    }
    return -1;
    }

  • @manup7636
    @manup7636 Před 2 lety

    very good explanation the tabs show how much u research for one question🙂

  • @avtardeepsingh6715
    @avtardeepsingh6715 Před 2 lety

    super..

  • @sanyamjain7058
    @sanyamjain7058 Před rokem

    is Time complexity is O(n^2) ?

  • @anujjain9273
    @anujjain9273 Před 2 lety

    i was just doing the mistake in the second while loop , btw nice explanation , but in the starting your voice was little crumbling , and have you made a git hub repo for interviewbit questions?

  • @meme_engineering4521
    @meme_engineering4521 Před 2 lety

    best explanation!!

  • @Your_Boy_Suraj
    @Your_Boy_Suraj Před rokem

    Python Solution:
    class Solution:
    # @param A : list of integers
    # @param B : integer
    # @return an integer
    def solve(self, A, B):
    count = 0
    i = 0
    n = len(A)
    while(i < n):
    right = min(n-1, i + B - 1)
    left = max(i - B + 1, 0)
    bulbFound = False
    while(right >= left):
    if A[right] == 1:
    bulbFound = True
    break
    right -= 1
    if bulbFound == False:
    return -1
    else:
    count += 1
    i = right + B
    return count

  • @shilpapatil1963
    @shilpapatil1963 Před rokem

  • @dilipparmar3175
    @dilipparmar3175 Před 2 lety

    Can you please upload your code also? It will help us with revision purposes.

  • @MayankKumar-nn6us
    @MayankKumar-nn6us Před 2 lety

    can anyone tell me what will be the time complexity? Is it O(n^2)?

    • @vedantupadhyay42
      @vedantupadhyay42 Před 10 měsíci

      O(N).
      The worst case : -
      A = [0, 0, 0, 0], B = 1
      We would have to iterate over every element..

  • @aniketsinghvats767
    @aniketsinghvats767 Před 2 lety

    Wow thanks for the solution. It was an easy question how can't I do that. ;_;

  • @dhananjoydey1337
    @dhananjoydey1337 Před 2 lety

    can you please upload solution of Leetcode problem "127. Word Ladder"?

  • @akshayrathod7679
    @akshayrathod7679 Před 2 lety

    How much avg time did you take to solve questions?

  • @Lifeisgood108-33
    @Lifeisgood108-33 Před 2 lety

    Make a tutorial on how to be focussed to see the main screen while watching your lectures.

    • @ayushnath3768
      @ayushnath3768 Před 2 lety +1

      Keep a mirror to the side where you can see your own reflection.

  • @masseffect0128
    @masseffect0128 Před 2 lety

    Idiots setting the corridor from starting index 1, while the array of lights starts from 0.
    here is the one pass for starting index 0;
    int i, end = -1, cnt = 0;
    for (i = 0; i < A.size();)
    {
    if (A[i] == 1)
    {
    if (i - B + 1 > end + 1)
    return -1;
    end = i + B - 1;
    i += i + B;
    ++cnt;
    }
    else
    ++i;
    }
    return cnt;

  • @ramaniruth6792
    @ramaniruth6792 Před 2 lety

    Nicely explained

  • @RehanShaikh-sz4mh
    @RehanShaikh-sz4mh Před 2 lety

    thank you so much ma'am , I was not getting the problem I was afraid when I have read this problem need DP and backtracking concept and I have not yet studied it thank you so much for the confidante by your explanation I have got the problem