MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / findFirstAndLast

Function findFirstAndLast

CPP/recursion/first_occur.cpp:8–23  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6#define mod 1000000007
7#define endl '\n'
8void findFirstAndLast(int arr[], int n, int x)
9{
10 int first = -1, last = -1;
11 for (int i = 0; i < n; i++) {
12 if (x != arr[i])
13 continue;
14 if (first == -1)
15 first = i;
16 last = i;
17 }
18 if (first != -1)
19 cout << "First Occurrence = " << first
20 << "\nLast Occurrence = " << last;
21 else
22 cout << "Not Found";
23}
24int main(){
25 cin.tie(0)->sync_with_stdio(0);
26 int arr[]={1,2,4,4,4,6};

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected