Help me in solving FIRSTANDLAST problem

My issue

in this que. why we cannot use sort(a,a+n)

My code

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	     int n;
	   int a[n];
	    for( int i=0;i<n;i++){
	   // sort(a,a+n);
	return 0;

Problem Link: FIRSTANDLAST Problem - CodeChef

Because u are rotating the whole array so sort function will disturb the elements position and thus will give to wrong output .

i think according to que. we given an array & we rotate it to find max val a[0]+a[n-1]
but my que. is why we rotate i don’t understand that part where ans also coming from shorting

We rotate the array to place maximum two consecutive values at a[n-1] and a[0] .
like 1 2 4 5 3 when u right rotate it two time it will become 5 3 1 2 4 and thus u will get 5+4 as maximum a[n-1]+a[0] value.