aboutsummaryrefslogtreecommitdiff
path: root/challenge-244/lubos-kolouch/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-244/lubos-kolouch/python')
-rw-r--r--challenge-244/lubos-kolouch/python/ch-1.py25
-rw-r--r--challenge-244/lubos-kolouch/python/ch-2.py23
2 files changed, 48 insertions, 0 deletions
diff --git a/challenge-244/lubos-kolouch/python/ch-1.py b/challenge-244/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..50799f5339
--- /dev/null
+++ b/challenge-244/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,25 @@
+from typing import List
+
+
+def count_smaller(nums: list[int]) -> list[int]:
+ """
+ Count the number of elements smaller than the current element at each index.
+
+ Args:
+ nums (List[int]): An array of integers.
+
+ Returns:
+ List[int]: An array containing the counts.
+ """
+ n = len(nums)
+ result = []
+ for i in range(n):
+ count = sum(1 for j in range(n) if nums[j] < nums[i] and j != i)
+ result.append(count)
+ return result
+
+
+# Tests
+assert count_smaller([8, 1, 2, 2, 3]) == [4, 0, 1, 1, 3]
+assert count_smaller([6, 5, 4, 8]) == [2, 1, 0, 3]
+assert count_smaller([2, 2, 2]) == [0, 0, 0]
diff --git a/challenge-244/lubos-kolouch/python/ch-2.py b/challenge-244/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..2968b5c1d8
--- /dev/null
+++ b/challenge-244/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+
+import unittest
+from itertools import combinations
+from typing import List
+
+
+def group_hero_power(nums: list[int]) -> int:
+ total_power = 0
+ for i in range(1, len(nums) + 1):
+ for combo in combinations(nums, i):
+ total_power += max(combo) ** 2 * min(combo)
+ return total_power
+
+
+# Tests
+class TestGroupHeroPower(unittest.TestCase):
+ def test_example(self):
+ self.assertEqual(group_hero_power([2, 1, 4]), 141)
+
+
+if __name__ == "__main__":
+ unittest.main()