Skip to content

Instantly share code, notes, and snippets.

@mridubhatnagar
Created May 20, 2018 08:07
Show Gist options
  • Save mridubhatnagar/4c7910b12ff67266b2dff423d50ddbfd to your computer and use it in GitHub Desktop.
Save mridubhatnagar/4c7910b12ff67266b2dff423d50ddbfd to your computer and use it in GitHub Desktop.
ref link: https://www.hackerrank.com/challenges/the-birthday-bar/problem
Approach 1: 3 Test Cases Passed
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the solve function below.
def solve(n, s, d, m):
count=0
for pos, val in enumerate(s):
if len(s) > 1:
for j in range(pos+1, m+1):
sum = val+s[j]
if sum == d:
count=count+1
else:
if val == d:
count = count+1
print(count)
if __name__ == '__main__':
#fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input())
s = list(map(int, input().rstrip().split()))
dm = input().split()
d = int(dm[0])
m = int(dm[1])
result = solve(n, s, d, m)
#fptr.write(str(result) + '\n')
#fptr.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment