Solution for similar arrays