Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
If a segment contains a value, it must contain all occurrences of the same value.
Partition the array into segments making each one as short as possible. This can be achieved by two-pointers or using a Set.
If we have <code>m</code> segments, we can arbitrarily group the neighboring segments. How many ways are there to group these <code>m</code> segments?