Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 6560 |

@blackshadows | 6400 |

@mb1973 | 5777 |

@Quandray | 5275 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5074 |

@kirtidee18 | 4408 |

@sanjay05 | 3762 |

@mantu_singh | 3666 |

@gfgaccount | 3605 |

@marius_valentin_dragoi | 3525 |

Complete Leaderboard | |

Handle | Score |

@anish5256 | 991 |

@vimleshpratapsingh321 | 980 |

@skj7 | 953 |

@kanewilliamson123 | 894 |

@pradeeppatidar1999 | 868 |

@akhileshkumar562002 | 862 |

@wallflowe101 | 826 |

@pd420786 | 813 |

@infilooop | 800 |

@bunnybug320 | 796 |

@nikhilkushwah280 | 796 |

Complete Leaderboard |

In a given array **A[]** find the maximum value of **(A[i] – i) - (A[j] – j)** where **i** is not equal to **j**.

**i** and **j** vary from **0** to **N-1** and **N** is the size of input array **A[]**. The value of **N** is always greater than **1**.

**Example 1:**

InputN = 5 A[] = {9, 15, 4, 12, 13}Output12Explanation:(a[1]-1) - (a[2]-2) = (15-1)-(4-2) = 12

**Example 2:**

**Input**
N = 4
A[] = {3, 1, 2, 4}
**Output**
3
**Explanation:**
(a[1]-1) - (a[2]-2) = (3-1)-(1-2) = 3

**Your Task: **

You don't need to read input or print anything. Your task is to complete the function **maxVal()** which takes the array **A[]** and its size **N**** **as inputs and returns the maximum value

**Expected Time Complexity:** O(N)

**Expected Auxiliary Space:** O(1)

**Constraints:**

2 ≤ N ≤ 10^{5}

1 ≤ A[i] ≤ 10^{5}

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...

Max value

...