Skills101
← All practice quizzes

Quiz: Kadane's Algorithm

5 questions · new set on every retakeNo time limitPass: 60%+10 XP on first pass

Find the largest sum of a contiguous subarray in one pass. Why "extend or restart" works, how to return the subarray itself, the all-negative case, and the variants interviewers ask next.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What does this print?

    a = [3, -4, 5, -1, 2]
    cur = best = a[0]
    for x in a[1:]:
        cur = max(x, cur + x)
        best = max(best, cur)
    print(best)
    
  2. Question 2

    In Kadane's algorithm, when does the current subarray "restart" at x?

  3. Question 3

    What is the maximum subarray sum of [-5, -2, -7] (subarrays must be non-empty)?

  4. Question 4

    What are the time and extra space of Kadane's algorithm?

  5. Question 5

    For the maximum CIRCULAR subarray, a wrapping subarray's best sum equals:

🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?24 students have taken today’s challengeTake today’s challenge →