| 6 | #define mod 1000000007 |
| 7 | #define endl '\n' |
| 8 | void 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 | } |
| 24 | int main(){ |
| 25 | cin.tie(0)->sync_with_stdio(0); |
| 26 | int arr[]={1,2,4,4,4,6}; |