Find first and last occurrence in sorted array | Applied Interview Question