Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
First, record the last occurrence index of each character. Then scan left to right, extending the current partition end to the maximum last-occurrence of any character seen so far. When the current index equals the partition end, the partition is complete.
A partition is valid when every character within it has its final occurrence inside that partition. Tracking the farthest last-occurrence ensures no character spans two partitions.
Updated Feb 2026