Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5704 |

@Quandray | 5245 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5046 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3523 |

@mantu_singh | 3510 |

@sushant_a | 3459 |

Complete Leaderboard | |

Handle | Score |

@cfwong8 | 1134 |

@gurshehzadsingh | 676 |

@nithinreddy3210 | 610 |

@Run_for_life | 570 |

@divyagupta221100 | 557 |

@jha8768 | 553 |

@AkashLahoty | 537 |

@aayushdesai01 | 526 |

@riyakumaribkj | 524 |

@amansinha74458 | 503 |

@dreamerdreamer | 488 |

Complete Leaderboard |

Given an array **arr** of size **N**, the task is to modify values of this array in such a way that the sum of absolute differences between two consecutive elements is maximized. If the value of an array element is X, then we can change it to either 1 or X. Find the maximum possible value of the sum of absolute differences between two consecutive elements.

**Example 1:**

Input: N = 4, arr[] = [3, 2, 1, 4, 5]Output:8Explanation: We can modify above array as arr[] = [3, 1, 1, 4, 1] Sum of differences = |1-3| + |1-1| + |4-1| + |1-4| = 8 Which is the maximum obtainable value among all choices of modification.

**Input: **N = 2, arr[] = {1, 5}
**Output: **4
**Explanation**: No modification required

**Your Task: **

You don't need to read input or print anything. Complete the function ** maximumDifferenceSum() **which takes

1 ≤

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Modify array to maximize sum of adjacent differences

...