forked from TanavShah/Data-Structures-And-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperations on Array
More file actions
40 lines (36 loc) · 715 Bytes
/
Operations on Array
File metadata and controls
40 lines (36 loc) · 715 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
//dsc(DEEPANSHU SINGH CHAUHAN)
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
ll n,s=0;
cin>>n ; //Size of Array
ll a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
ll index1,index2;
cin>>index1>>index2;
sort(a+index1,a+index2+1);
cout<<"Minimum Value:"<<a[index1]<<endl;
cout<<"Maximum Value:"<<a[index2]<<endl;
for(int i=index1;i<=index2;i++)
{
s=s+a[i];
a[i]=a[i]+4;
}
cout<<"Sum:"<<s<<endl;
cout<<"Updated Array:"<<endl;
for(int i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
return 0;
}
/*
Time Complexity of this method in Worst case wouls be
O(nlogn+n)
*/