CarlosLabs
Hackerrank Challenges - Birthday chocolate
(CM) A verbose and pudgy solution.
#!/bin/python3 import math import os import random import re import sys # Complete the birthday function below. def birthday(s, d, m): ac = 0 il = len(s) ix = 0 while (ix < il): aux = 0 ix2 = 0 while (ix2 < m): ptr = (ix + ix2) ##print("aux:", aux," ptr:",ptr," ix:",ix," ix2:",ix2,"ac:",ac) if (ptr < il): aux=aux+s[ptr] ##print(s[ptr]) if (ix2==(m-1)) and (aux == d): ac +=1 ##print("match!") ix2 += 1 ix+=1 return ac if __name__ == '__main__': fptr = open(os.environ['OUTPUT_PATH'], 'w') n = int(input().strip()) s = list(map(int, input().rstrip().split())) dm = input().rstrip().split() d = int(dm[0]) m = int(dm[1]) result = birthday(s, d, m) fptr.write(str(result) + '\n') fptr.close()