-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathtwopointer.py
More file actions
44 lines (40 loc) · 775 Bytes
/
twopointer.py
File metadata and controls
44 lines (40 loc) · 775 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
39
40
41
42
43
44
# T.C = O(N)
def isPalindrome(s):
# start
i = 0
# end
j = len(s)-1
while i < j:
if s[i] != s[j]:
return False
i=i+1
j=j-1
return True
'''
t = int(input())
for i in range(t):
s = str(input())
print(isPalindrome(s))
'''
def twoSum(a,target):
# start
i = 0
# end
j = len(a)-1
while i < j:
sm = a[i] + a[j]
if target == sm:
print("{} {}".format(a[i],a[j]))
print("{} {}".format(i,j))
return True
elif sm < target:
i=i+1
else:
j=j-1
return False
t = int(input())
for i in range(t):
a =list(map(int,input().split()))
target = int(input())
print(a)
print(twoSum(a,target))