Amazon Interview Question || SDE-1/SDE-2 (2024)

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2024-07-26Added By Anonymous
Source: Link

Company: Amazon
Role: SDE I / SDE II
Interview Stage: Phone Screen
Location: unknown
Year: 2024

Original Post Content:

I have an tests array of

tests = [a,b,c,d,e,f,g....,x,y,z]

I have a function hasFailure(arr) that takes in an array of elements to check if there are any failed tests (assume hasFailure is implemented for you and somehow has constant time complexity). hasFailure returns true if all the tests pass, and fails if a single test fails. How can I find which test is failing? The tests array is not sorted and is not empty and there is 1 failing test.

Example:
tests = [a,b,c,d,e,f,g....,x,y,z] and all tests pass except for z.

hasFailure(['z']) --> true
hasFailure(['a', 'b', 'z']) --> true
hasFailure(['a', 'b', 'f']) --> false

Your solution should return ['z']

Follow-up:
What if there are multiple failing tests?
What if tests is sorted?

Comments