Skip to content

Instantly share code, notes, and snippets.

@imAryanSingh
Last active May 8, 2025 12:44
Show Gist options
  • Select an option

  • Save imAryanSingh/6f0cf81c989b7c69562a8611d5d0d11c to your computer and use it in GitHub Desktop.

Select an option

Save imAryanSingh/6f0cf81c989b7c69562a8611d5d0d11c to your computer and use it in GitHub Desktop.
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()
@imAryanSingh
Copy link
Author

imAryanSingh commented May 7, 2025

HENNGE Backend Challenge Solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment