From 152fea16a8a4fe8e2693adf0ecae38570d874783 Mon Sep 17 00:00:00 2001 From: Mohd Musaiyab <106825955+MohdMusaiyab@users.noreply.github.com> Date: Sat, 3 Jun 2023 21:59:09 +0530 Subject: [PATCH] Create First and Last occurrence of X --- First and Last occurrence of X | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 First and Last occurrence of X diff --git a/First and Last occurrence of X b/First and Last occurrence of X new file mode 100644 index 0000000..64727ae --- /dev/null +++ b/First and Last occurrence of X @@ -0,0 +1,31 @@ + vector find(int arr[], int n , int x ) +{ + // code here + vector ans; + + for(int i=0;i=0;i--) + { + if(arr[i]==x) + { + ans.push_back(i); + break; + } + } + if(ans.size()==0) + { + ans.push_back(-1); + ans.push_back(-1); + return ans; + } + else{ + return ans; + } +}