So far the only solution that correctly addresses your requirement (returning the duplicated value(s), not returning a duplicates-removed array) was the answer submitted by vimalkumars above. I will provide my version here, slightly cleaner (imho) and…