#K83182. Find the Hidden Treasure
Find the Hidden Treasure
Find the Hidden Treasure
You are given a sequence of caves represented by integers. In this sequence, each cave contains a key that points to the next cave. A value of \( -1 \) indicates that the cave contains the hidden treasure.
Your task is to find the index of the cave (0-indexed) where the treasure is hidden, i.e. the first occurrence of \( -1 \) in the sequence. Formally, given an array \( keys \) of length \( n \), find the smallest index \( i \) such that \( keys[i] = -1 \).
inputFormat
The first line contains an integer \( n \) representing the number of caves.
The second line contains \( n \) space-separated integers, where each integer represents the value in the cave. A value of \( -1 \) indicates that the cave holds the treasure.
outputFormat
Output a single integer representing the index (0-indexed) of the cave where the treasure is hidden, which is the index of the first occurrence of \( -1 \) in the input list.
## sample1
-1
0