For this Question: You are given an array with all distinct elements which include all elements of a binary search tree in an increasing order manner (in-order traversal). But 2 element swapped their position. we have to print the sum of two swapped nodes.The first line contains a single integer N.
The second line contains N space-separated integer A[i].
Print sum of exchanged node value.Sample Input 1:
1 2 3 4 5 7 6

Sample Output 1:
13


Explanations:
if we draw a BST from given array than we can observe that element 6 and 7 had swapped their position.
So sum of these 2 is equal to 13., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int arr[n],brr[n];
for(int i=0;i<n;i++)cin>>arr[i],brr[i]=arr[i];
sort(arr,arr+n);
int sum=0;
for(int i=0;i<n;i++){
if(arr[i]!=brr[i])sum+=arr[i];
}
cout<<sum<<endl;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not?