Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #User function Template for python3
- #Function to find a continuous sub-array which adds up to a given number.
- class Solution:
- def subArraySum(self,arr, n, s):
- l,r,sum=0,1,arr[0]
- while r<=n:
- while sum>s:
- sum-=arr[l]
- l+=1
- if sum==s:
- return [l+1,r]
- break
- else:
- if r<n:
- sum+=arr[r]
- r+=1
- if r>n:
- return [-1]
- #{
- # Driver Code Starts
- #Initial Template for Python 3
- import math
- def main():
- T=int(input())
- while(T>0):
- NS=input().strip().split()
- N=int(NS[0])
- S=int(NS[1])
- A=list(map(int,input().split()))
- ob=Solution()
- ans=ob.subArraySum(A, N, S)
- for i in ans:
- print(i, end=" ")
- print()
- T-=1
- if __name__ == "__main__":
- main()
- # } Driver Code Ends
Advertisement
Add Comment
Please, Sign In to add comment