Header Ads Widget

Simple Search

Problem:-

Problem

Given a List of Distinct N number a1,a2,a3........an.
Find The Position Of Number K In The Given List.

Input Format

First Line Take Input Value Of N

Second Line Take Input N Space Separated Integer Value

Third Line Take Input Value Of K

Output Format

Position Of K In The Given List

Constraints

  • 0 < N < 100001
  • 0 < ai < 1010
  • 0 < K < 1010

NOTE:
Array Indexing Starts From 0

Sample Input
5
1 2 3 4 5
4
Sample Output
3
Time Limit: 1
Memory Limit: 256
Source Limit:

Code:- 

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long int a[n],k;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    cin>>k;
    for(int i=0;i<n;i++)
    {
        if(a[i]==k)
        {
            cout<<i;
            break;
        }
    }
    return 0;
}




Post a Comment

0 Comments