Created
May 21, 2025 19:11
-
-
Save jac18281828/f0e0d78bf46143ce0114997934300cfb to your computer and use it in GitHub Desktop.
hackerrank acmTeam
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import List, Tuple | |
| def bitstrToInt(bs: str) -> int: | |
| """Convert bitstring bs to an integer""" | |
| return int(bs, 2) | |
| def countBits(d: int) -> int: | |
| """Count the bits in d and return that value""" | |
| return bin(d).count("1") | |
| def acmTeam(topic: List[str]) -> Tuple[int, int]: | |
| n_topic = 0 | |
| n_team = 0 | |
| topic_value = [bitstrToInt(t) for t in topic] | |
| for i, ti in enumerate(topic_value): | |
| for j, tj in enumerate(topic_value): | |
| if j <= i: | |
| continue | |
| topic_count = countBits(ti | tj) | |
| if topic_count > n_topic: | |
| n_topic = topic_count | |
| n_team = 1 | |
| elif topic_count == n_topic: | |
| n_team += 1 | |
| else: | |
| continue | |
| return n_topic, n_team | |
| if __name__ == "__main__": | |
| topics = ["10101", "11110", "00010"] | |
| topics = ["10101", "11100", "11010", "00101"] | |
| n_sub, n = acmTeam(topics) | |
| print(f"{n_sub} {n}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment