GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Sunday, 5 June 2022

[Solution] First and Last CodeChef Solution | CodeChef Problem Solution 2022

You are given an array A=[A1,A2,,AN] of length N.

You can right rotate it any number of times (possibly, zero). What is the maximum value of A1+AN you can get?

Note: Right rotating the array [A1,A2,,AN] once gives the array [AN,A1,A2,,AN1]. For

Solution Click Below:-  CLICK HERE


example, right rotating [1,2,3] once gives [3,1,2], and right rotating it again gives [2,3,1].

Input Format

  • The first line of input will contain a single integer T, denoting the number of test cases. The description of the test cases follows.

  • The first line of each test case contains a single integer N, denoting the length of array A.
  • The second line of each test case contains N space-separated integers A1,A2,,AN — denoting the array A.

Output Format

For each test case, output on a new line the maximum value of A1+AN you can get after several right rotations.

Constraints

  • 1T1000
  • 2N105
  • 1Ai109
  • The sum of N across all test cases does not exceed 

No comments:

Post a Comment