Leetcode 797 Solution
This article provides solution to leetcode question 797 (rabbits-in-forest)
Access this page by simply typing in "lcs 797" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/rabbits-in-forest
Solution
class Solution:
def numRabbits(self, answers: List[int]) -> int:
m = collections.defaultdict(int)
for a in answers:
m[a] += 1
ans = 0
for k, v in m.items():
if k == 0:
ans += v
else:
ans += ((v + k) // (k + 1)) * (k + 1)
return ans