first and last occurance of an array (medium)