We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f1477c8 commit 4d5a427Copy full SHA for 4d5a427
8 May Missing element of AP
@@ -0,0 +1,29 @@
1
+class Solution {
2
+ public:
3
+
4
+ int findMissing(vector<int> &arr) {
5
+ // code here
6
+ int diff=arr[1]-arr[0];
7
8
+ if(diff>0){
9
+ for(int i=1;i<arr.size()-1;i++)
10
+ {
11
+ int d=arr[i+1]-arr[i];
12
+ if(d==diff) continue;
13
+ if(diff>d) return arr[i]-d;
14
+ else if(diff<d) return arr[i]+diff;
15
+ }
16
17
+ else{
18
19
20
21
22
+ if(diff<d) return arr[i]-d;
23
+ else if(diff>d) return arr[i]+diff;
24
25
26
27
+ return *(arr.end()-1)+diff ;
28
29
+};
0 commit comments