forked from Srinivas11789/AlgorithmNuggets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrive.py
More file actions
43 lines (35 loc) · 815 Bytes
/
arrive.py
File metadata and controls
43 lines (35 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Codility problem - arrive at a k value
def solution(K, A):
# write your code in Python 3.6
"""
n = len(A)
count = 0
match = []
for i in range(n):
if K - A[i] in A[i:]:
match.append((i,A.index(K-A[i])))
count += 1
if i != A.index(K-A[i]):
count += 1
#print(match)
return count"""
n = len(A)
count = 0
for i in range(n):
for j in range(i,n):
if A[i] + A[j] == K:
count += 1
if i != j:
count += 1
return count
"""
n = len(A)
count = 0
for i in range(n):
#print(i)
for j in range(n):
if A[i] + A[j] == K:
#print(i,j)
count += 1
return count
"""