aboutsummaryrefslogtreecommitdiff
path: root/challenge-244/lubos-kolouch/python/ch-1.py
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-11-24 22:06:16 +0000
committerGitHub <noreply@github.com>2023-11-24 22:06:16 +0000
commit70cd7d1c7ac8258aa41caecb622d0c1284d7cf30 (patch)
treef6562c7dd52b3c11b758d1caa7120f8ba6aab979 /challenge-244/lubos-kolouch/python/ch-1.py
parentd931ba7fbb2d57ca1e5123ea29b80f1c0dbc28e5 (diff)
parent73b1c7ec14481d7163a6f882f6450fa526813d2d (diff)
downloadperlweeklychallenge-club-70cd7d1c7ac8258aa41caecb622d0c1284d7cf30.tar.gz
perlweeklychallenge-club-70cd7d1c7ac8258aa41caecb622d0c1284d7cf30.tar.bz2
perlweeklychallenge-club-70cd7d1c7ac8258aa41caecb622d0c1284d7cf30.zip
Merge pull request #9121 from LubosKolouch/master
feat(challenge-244/lubos-kolouch/perl,python,raku,blog): Challenge 244 LK Perl Python Raku blog
Diffstat (limited to 'challenge-244/lubos-kolouch/python/ch-1.py')
-rw-r--r--challenge-244/lubos-kolouch/python/ch-1.py25
1 files changed, 25 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]