Last active
May 8, 2025 12:44
-
-
Save imAryanSingh/6f0cf81c989b7c69562a8611d5d0d11c to your computer and use it in GitHub Desktop.
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
| def main(): | |
| import sys | |
| def power_four(n): | |
| return n * n * n * n | |
| def process_test_case(numbers, index, acc): | |
| if index >= len(numbers): | |
| return acc | |
| if numbers[index] > 0: | |
| return process_test_case(numbers, index + 1, acc) | |
| return process_test_case(numbers, index + 1, acc + power_four(numbers[index])) | |
| def handle_test_case(lines, index, results): | |
| if index >= len(lines): | |
| return results | |
| x_line = lines[index] | |
| nums_line = lines[index + 1] if index + 1 < len(lines) else "" | |
| try: | |
| x = int(x_line) | |
| numbers = list(map(int, nums_line.strip().split())) | |
| except: | |
| return handle_test_case(lines, index + 2, results + [-1]) | |
| if len(numbers) != x: | |
| result = -1 | |
| else: | |
| result = process_test_case(numbers, 0, 0) | |
| return handle_test_case(lines, index + 2, results + [result]) | |
| input_lines = sys.stdin.read().strip().splitlines() | |
| if not input_lines: | |
| return | |
| try: | |
| n = int(input_lines[0]) | |
| except: | |
| return | |
| output = handle_test_case(input_lines[1:], 0, []) | |
| for value in output: | |
| print(value) | |
| if __name__ == "__main__": | |
| main() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HENNGE Backend Challenge Solution