Largest Combination With Bitwise AND Greater Than Zero - Leetcode 2275 - Python

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

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

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

    Bro has insider information

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

    My O(n^2) beats 90% on time complexity, and 5% on memory complexity. For a guy that never do bit manipulation i will take it

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

    In approach 2, instead of shifting 1 to left i times and checking if AND result is not 0, we can also shift num to right by i and AND with 1, result will be always 0 or 1 , exactly what we need to add in curr counter, which removes inner if condition.
    public int largestCombination(int[] nums) {
    int ans = 0;
    for(int i = 0; i < 24; i++){
    int curr = 0;
    for(int num : nums){
    curr += (num >> i) & 1;
    }
    ans = Math.max(ans, curr);
    }
    return ans;
    }

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

    Per the constraints 24 loops are ok:
    def largestCombination(self, candidates: List[int]) -> int:
    largest = 0
    for i in range(24):
    curr = 0
    for n in candidates:
    if (1

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

      Would it really affect the time complexity? It's already O(1) in the outer loop with 32 iterations ...

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

      @@nodeUser same time complexity but better runtime

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

    You are amazing I don't know what more to say.

  • @himanshurane-m6j
    @himanshurane-m6j 2 месяца назад

    Thanks

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

    This problem is actually simple

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

    bro wtf 😭 my brain hurts. i am trying to keep a daily streak but these types of problems makes it hard. please make tomorows problem easy for us noobs sake

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

    thanks :)

  • @IshwaryaP-zo5jk
    @IshwaryaP-zo5jk 2 месяца назад +1

    you are really amazing . I am following you channel daily, i won't deny that i get better by the way you teach.keep the good work!

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

    A little confused here. How we are sure that the maximum would be 32? is it due to integer being 4 bytes or am i missing something?

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

      An int, -2147483648 to 2147483647, uses 4 bytes(32 bits) for storage.

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

    That second method with fixing a position and then counting the number of candidates that had a 1 in that position was really clever! I'm a bit surprised the run time was so much slower though. Perhaps setting the position to a variable (eg. have pos = 1, and then at the end of each loop update pos = pos

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

    I tried solving with a decision tree and I blocked trying to optimize it with DP. Turned out the answer is a lot simpler.

  • @MehmetDemir-xi3yy
    @MehmetDemir-xi3yy 2 месяца назад +6

    Hey man I had fired you being papa neetcode recently (because Papas do not skip days) but you are close to getting that title again.

  • @sheng-yanzhang4114
    @sheng-yanzhang4114 2 месяца назад +3

    claude gave me the same solution, but i only can understand after i wathcing this video😜

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

    lol how is that even possible

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

      Love finds a way ❤️
      My love for leetcode, that is.