Apple | Phone | First Element that Appears Once
Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2020-06-04Added By Anonymous
Source: Link
Had a phone screen with Apple a month or so ago for Safari UI Software Engineer role.
yoe: 2 years
level: ict3
location: Apple Park
length: 45 minutes
Note: Was asked to use Swift/C/Objective-C for this interview.
5 minutes:
Q1 - Given a non sorted array of integers, return the first number that appears once in the array.
Solved using hashmap with O(n) space and O(n) time
1arr = [1,2,3,4,5,6,1,2,3,6,7]
2return 4
3Explanation:
4numbers 4, 5, 7 have frequency of 1 but 4 is the first.5 minutes: follow up. What if the array is sorted?
Solved with O(n) time and O(1) space. Not sure if this can be solved in log(n) ?
1arr = [1,1,2,2,3,3,4,5,6,6,7]
2return 4I spent the rest of the 35 minutes chatting with the interviewer. Never heard back from them.