HackerRank Backend Engineer AI Interview
Anonymous User
1393

I applied directly

Received a OA link -

it has 3 questions

Part 1 - Given an binary array containing only 0 and 1 find the length of longest contiguous subarray in which the number of 0s and 1s is equal Ex =[0,1,0,0,1,1,0] answer is 6

Part 2 - Now, you may flip at most one element in the array change a 0 to 1 or a 1 to 0 find the length of the longest subarray where the number of 0s equal the number of 1s after performing at most one flip Ex [0,1,0,0,1,1,0,0] ans is 8
Part 3 - For the final task, find the length of the longest subarray with an equal number of 0s and 1s such that every prefix of that subarray has the count of 1s greater than or equal to the count of 0s

Return the max length of a subarray that satisfies all the condition 

Ex - [1,0,1,1,0,0,1] ans is 6

After this AI asked me some questions

  1. explain the 3rd question approach
  2. What is the time and space complexity and could there be any scenarios where we might need to optimise the space further
  3. Final follow up if the input array contains values other than 0s and 1s how would you modify your code to handle such invalid inputs?

7208e527-bc64-460b-8e44-619e0ae5ba0a_1699708027.9374254.jpeg

Comments (2)