Skip to content

Commit b6ff587

Browse files
authored
Create Longest Sub-Array with Sum K Brute Force.py
1 parent 5e185cd commit b6ff587

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'''
2+
3+
Longest Sub-Array with Sum K
4+
https://practice.geeksforgeeks.org/problems/longest-sub-array-with-sum-k0809/1
5+
6+
'''
7+
8+
class Solution:
9+
def lenOfLongSubarr (self, A, N, K) :
10+
ans = 0
11+
for start in range(N):
12+
total = 0
13+
for end in range(start, N):
14+
total += A[end]
15+
if total == K:
16+
ans = max(ans, end-start+1)
17+
return ans
18+
19+
for _ in range(0,int(input())):
20+
21+
n, K = map(int , input().split())
22+
arr = list(map(int,input().strip().split()))
23+
ob = Solution()
24+
print(ob.lenOfLongSubarr(arr, n, K))
25+
26+

0 commit comments

Comments
 (0)