BackeasyArrays Paytm

Neon Grid Surveillance Solution

Problem Statement

Given a grid of 27 surveillance nodes, each containing a unique identifier, find the node that has been breached by the rogue AI.

Example 1
Input
[1, 2, 0, 4, 3, 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27]
Output
3

Explanation: Step-by-step: Given the input array [1, 2, 0, 4, 3, 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27], we iterate through the array to find the first occurrence of 0. The first occurrence of 0 is at index 3, so we return 3.

Example 2
Input
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27]
Output
-1

Explanation: Step-by-step: Given the input array [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27], we iterate through the array to find the first occurrence of 0. Since 0 is not found in the array, we return -1.

Constraints

  • 1 <= n <= 10^5
  • array elements are 0 or 1.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free