Maximum prefix sum after K reversals of a given array | C # program for the above approach ; Function to find the maximum prefix sum after K reversals of the array ; Stores the required sum ; If K is odd , reverse the array ; Store current prefix sum of array ; Traverse the array arr [ ] ; Add arr [ i ] to currsum ; Update maximum prefix sum till now ; Print the answer ; Driver Code ; Function Call
using System ; class GFG { static void maxSumAfterKReverse ( int [ ] arr , int K , int N ) { int sum = Int32 . MinValue ; if ( K % 2 != 0 ) Array . Reverse ( arr ) ; int currsum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { currsum += arr [ i ] ; sum = Math . Max ( sum , currsum ) ; } Console . Write ( sum ) ; } public static void Main ( string [ ] args ) { int [ ] arr = { 1 , 5 , 8 , 9 , 11 , 2 } ; int K = 1 ; int N = arr . Length ; maxSumAfterKReverse ( arr , K , N ) ; } }