Created
May 20, 2018 08:07
-
-
Save mridubhatnagar/4c7910b12ff67266b2dff423d50ddbfd 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
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