Friday, February 1, 2019

Searching Linear

  • Problem Description

    Write a program to search a element linearly
  • CODING ARENA
  • a=int(input())
    x=[]
    for i in range(a):
        b=int(input())
        x.append(b)
    key=int(input())
    for i in range(a):
        if(key==x[i]):
            print("Element is present at index",i)
            break
  • Test Case 1

    Input (stdin)
    5
    
    2
    
    3
    
    4
    
    10
    
    40
    
    3
    
    
    Expected Output
    Element is present at index 1
  • Test Case 2

    Input (stdin)
    5
    
    2
    
    3
    
    4
    
    10
    
    40
    
    10
    
    
    Expected Output
    Element is present at index 3

No comments:

Post a Comment