Python Program Search Element in Array || How to search an element in an array in Python

Опубликовано: 03 Октябрь 2024
на канале: Zeeshan_Tutorial
485
19

Simply traverse through the array and check if k matches the element of the array, if it matches return the index of that element.

Approach:
Traverse through the array.
If arr[i] matches k then return I.

Example 1:
Input: array[] = {1,2,3,4,5} k=3
Output: 2
Explanation: The answer is 2 because 3 is present at 2nd index.

Example 2:
Input: array[]={6,7,9,5,3,10} k=10
Output: 5
Explanation: The answer is 5 because 10 is present at 5th index.

#python
#searchelement
#programming
#Zeeshan_Tutorial