Leetcode - Max Number of K-Sum Pairs (Python)

Поделиться
HTML-код
  • Опубликовано: 5 окт 2024
  • January 2021 Leetcode Challenge
    Leetcode - Max Number of K-Sum Pairs #1679

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

  • @janmichaelaustria620
    @janmichaelaustria620 3 года назад +1

    The edge cases threw me for a fit on this problem! I didn't think about using a seen set - that was cool! I just updated the hashmap in place. Thanks Tim!
    counts = Counter(nums)
    pairs = 0
    for num in nums:
    #find the complement
    complement = k - num
    if complement in counts:
    #edge case 1, enough elements
    if counts[num] > 0 and counts[complement] > 0:
    #edge case when they are the same and count at nums < 2
    if num == complement and counts[num] < 2: #we need two of the same
    continue
    pairs += 1
    counts[num] -= 1
    counts[complement] -= 1
    return pairs

    • @timc3406
      @timc3406  3 года назад

      Nice work Jan! It's really cool to see different efficient approaches

  • @tarsco4235
    @tarsco4235 Год назад

    great video, i was also confused by the description. "remove them from the array" followed by "Return the maximum number of operations you can perform on the array." seems they only wanted to latter, and i solved this with a two pointer. thank you for the help!

  • @avichai987789
    @avichai987789 2 года назад +1

    Great video man!
    can you please write in the description of your videos the time and space complexity it would really help!

  • @pc2780
    @pc2780 3 года назад +1

    Hi, thanks a lot for your videos. You make problems look very simple. Could you please do videos for Leetcode weekly contest questions ?

    • @timc3406
      @timc3406  3 года назад

      Thanks for watching! II'll try someday but some of those hard questions are really really hard for me

  • @thatguy2514
    @thatguy2514 9 месяцев назад

    Good video bro, next time tho maybe slow down a little bit. 😀

  • @muzaffartursunov324
    @muzaffartursunov324 9 месяцев назад

    Super Great!!!