How would you like to learn today?
Visualize algorithms in real time, explore them step by step, or challenge yourself with a test.Choose a path to focus—or scroll down to preview all options.
Visualize the algorithm step-by-step with interactive animations in real time.
Read the full explanation, examples, and starter code at your own pace.
Drag and arrange the algorithm steps in the correct execution order.
🧠 Select Active to activate
Follow every state change, comparison, and transformation as the execution unfolds in real time.
📖 Select Passive to activate
Objective: Find the contiguous subarray within a given array that has the maximum sum using Kadane's algorithm.
Kadane's algorithm is a dynamic programming approach that efficiently solves this problem in O(n) time, where n is the number of elements in the array.
max_ending_here: Stores the maximum sum of a contiguous subarray ending at the current index.max_so_far: Stores the overall maximum sum of a contiguous subarray found so far.arr[i]) is greater than max_ending_here + arr[i], start a new subarray from the current element:max_ending_here = arr[i].max_ending_here = max_ending_here + arr[i].max_ending_here with max_so_far.max_ending_here is larger, update max_so_far:max_so_far = max(max_so_far, max_ending_here).max_so_far contains the maximum sum of a contiguous subarray.Input Array:
[-2, 1, -3, 4, -1, 2, 1, -5, 4]
-2
max_ending_here = -2max_so_far = -21
max_ending_here = 1max_so_far = 1-3
max_ending_here = -2max_so_far = 14
max_ending_here = 4max_so_far = 4-1
max_ending_here = 3max_so_far = 42
max_ending_here = 5max_so_far = 51
max_ending_here = 6max_so_far = 6-5
max_ending_here = 1max_so_far = 64
max_ending_here = 5max_so_far = 6Maximum Sum of a Contiguous Subarray: 6
🎯 Select Challenge to activate
Drag and arrange the algorithm steps in the correct execution order instead of spending time typing code letter by letter.
The algorithm is divided into three logical parts. Carefully rearrange each section in the correct order to form a complete and valid solution.
Understand Below AlgorithmGreen text means the instruction is placed in the correct position.
Red text means the instruction is in the wrong position.
Instructions with the same background color indicate particular blocks start and end.
A tick mark means the instruction is correct and locked.
🔒 Locked steps cannot be moved. Only unlocked steps are draggable.
🔊 Enable sound for swap feedback and completion effects.