HackerRank Interview Prep Kit - Problem 12: Sherlock and Anagrams

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ก.พ. 2025

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

  • @rawisglenn
    @rawisglenn 2 ปีที่แล้ว +2

    Hi why is the permuation for no of k anagram = (n -1)*k/2

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

      This is due to the combination formula, n!/r!(n-r)!. where “val” is “n” the number of objects in a set and “r” is 2 since we’re making pairs. So val!/2!(val-2)! = val(val-1)/2.

  • @amritansh92
    @amritansh92 3 ปีที่แล้ว +2

    You explain really well. 👏

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

    Great video! But was the if(val > 1) necessary at the end? Because if it 1, it'll just multiply by zero and it'll continue to work. Or did you do it for efficiency?

    • @briandyck8828
      @briandyck8828  3 ปีที่แล้ว +3

      It would still work without the check, it’s just there to make the code more efficient, and makes the logic a little more clear in my opinion

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

    I found the same number by doing this,
    sum(1 +....+ (value-1))