-2
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.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • 1
    This by looking at code and error, it seem there is no connection between them, Can you Specify more about the code and Error, Code seems to be incomplete. – Zoro Aug 17 '23 at 07:18
  • 2
    Does this answer your question? [An integer is required? open()](https://stackoverflow.com/questions/1046656/an-integer-is-required-open) also see: [Why is "import *" bad?](https://stackoverflow.com/questions/2386714/why-is-import-bad) and [Should wildcard import be avoided?](https://stackoverflow.com/questions/3615125/should-wildcard-import-be-avoided) – Abdul Aziz Barkat Aug 17 '23 at 07:55

0 Answers0