0
def max_logged_in(interval_lst,T):
    startArr, endArr = zip(*interval_lst)
    i = 0
    j = 0
    maxOverlap = 0
    currentOverlap = 0
    while (i<T and j<T):
        if (startArr[i] < endArr[j]):
            currentOverlap = currentOverlap + 1
            maxOverlap = max(maxOverlap, currentOverlap)
            i = i + 1
        else:
            currentOverlap = currentOverlap - 1
            j = j + 1

The code is supposed to run through the two arrays and find the max overlap give a list such as [(5,15), (18,25), (3,12), (4, 11), (1,15), (18,19)] in the given time (T). Running this code is giving me a tuple index error. I can't seem to figure out why it is giving me an index error.

4
  • 1
    If T > 5, then your if will cause the error you got. Commented Oct 20, 2016 at 1:18
  • Could you elaborate please? I'm having trouble understanding why. Commented Oct 20, 2016 at 1:38
  • what is the value of T? Commented Oct 20, 2016 at 2:21
  • It can be any random number. In this case it was 30. Commented Oct 20, 2016 at 3:47

1 Answer 1

1

If T is greater than the length of interval_lst, then i and/or j can get as high as that length, but there is no element in either startArr nor endArr at that index (since they are each the same length as interval_lst).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.