from os import *
from sys import *
from collections import *
from math import *
def getLongestSubarray(arr: [int], k: int) -> int:
# dictionary mydict implemented
# as hash map
mydict = dict()
n = len(arr)
# Initialize sum and maxLen with 0
sum = 0
maxLen = 0
# traverse the given array
for i in range(n):
# accumulate the sum
sum += arr[i]
# when subArray starts from index '0'
if (sum == k):
maxLen = i + 1
# check if 'sum-k' is present in
# mydict or not
elif (sum - k) in mydict:
maxLen = max(maxLen, i - mydict[sum - k])
# if sum is not present in dictionary
# push it in the dictionary with its index
if sum not in mydict:
mydict[sum] = i
return maxLen
Error:
Traceback (most recent call last):
File "runner.py", line 41, in file = open(os.environ['EXEC_COUNTER_FILE'], "w")
TypeError: an integer is required (got type str)
Tried to run this code in coding ninjas but showing the error I mentioned above.