Skip to content

Commit d59d5b0

Browse files
committed
Apr 20
1 parent a4627b8 commit d59d5b0

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

2025-04-April-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
| April 17 | [2176. Count Equal and Divisible Pairs in an Array](https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array/) | Easy | Solved |
2424
| April 18 | [38. Count and Say](https://leetcode.com/problems/count-and-say/) | Medium | Solved |
2525
| April 19 | [2563. Count the Number of Fair Pairs](https://leetcode.com/problems/count-the-number-of-fair-pairs/) | Medium | Solved |
26-
| April 20 | []() | | |
26+
| April 20 | [781. Rabbits in Forest](https://leetcode.com/problems/rabbits-in-forest/) | Medium | Solved |
2727
| April 21 | []() | | |
2828
| April 22 | []() | | |
2929
| April 23 | []() | | |
@@ -40,5 +40,5 @@
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
4242
| Easy | 6 | 6 | 0 |
43-
| Medium | 10 | 7 | 3 |
43+
| Medium | 11 | 8 | 3 |
4444
| Hard | 3 | 0 | 3 |
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from collections import Counter
2+
import math
3+
4+
5+
class Solution:
6+
def numRabbits(self, answers: list[int]) -> int:
7+
frequencies = Counter(answers)
8+
total = 0
9+
for answer, count in frequencies.items():
10+
size = answer + 1
11+
groups = math.ceil(count / size)
12+
total += groups * size
13+
return total
14+
15+
16+
def main():
17+
answers = [1, 1, 2]
18+
assert Solution().numRabbits(answers) == 5
19+
20+
answers = [10, 10, 10]
21+
assert Solution().numRabbits(answers) == 11
22+
23+
24+
if __name__ == '__main__':
25+
main()

0 commit comments

Comments
 (0)