-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy patharray_basic.cpp
More file actions
46 lines (39 loc) · 821 Bytes
/
array_basic.cpp
File metadata and controls
46 lines (39 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[10] = {1,2,3};
for(int i=0;i<5;i++)
{
cin>>a[i];
}
for(int i=0;i<10;i++)
{
cout<<a[i]<<" ";
}
// size of array
cout<<endl<<sizeof(a)<<endl;
// size of single element
cout<<sizeof(a[0])<<endl;
// no. of element
cout<<sizeof(a)/sizeof(int)<<endl;
return 0;
}
class Solution {
public:
vector<int> findClosestElements(vector<int>& arr, int k, int x) {
int l=0;
int r = arr.size()-1;
while(r-l>=k)
{
if(x-arr[l]<=arr[r]-x)
{
r--;
}
else{
l++;
}
}
return vector<int>(begin(arr)+l,begin(arr)+r+1);
}
};