NA, please ignore my comments.
Can you explain code? your solution is concise, but not straightforward.
you must remove this line: if(arr[i+1] == arr[j+1]) next[i+1] = next[j+1];
With this line, the next array is wrong.
i like this answer, it is easy and clear.
very impressive usage of return value of put().
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.