Editorial for Spotting In Sequence


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Python:

a = int(input())
n = int(input())
nums = list(map(int, input().split()))

for i in range(n):
    if nums[i] == a:
        print(i)
        break
else:
    print(-1)

C++:

#include <bits/stdc++.h>
using namespace std;

int main() {
    int a, n;
    cin >> a >> n;

    vector<int> nums(n);
    for (int i = 0; i < n; i++) cin >> nums[i];

    for (int i = 0; i < nums.size(); i++) {
        if (nums[i] == a) {
            cout << i << "\n";
            return 0;
        }
    }

    cout << "-1\n";
}

Comments

There are no comments at the moment.