Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5646 |

@Quandray | 5233 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4716 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3413 |

Complete Leaderboard | |

Handle | Score |

@skj7 | 671 |

@gurshehzadsingh | 418 |

@swastik8750 | 411 |

@nishunishuraj18 | 405 |

@vedantvalsangkar | 390 |

@deepakchowdary | 380 |

@akashverma4 | 369 |

@satyamannsm | 353 |

@2018uec1603 | 341 |

@rkrupeshkumar345 | 335 |

@surajmamgai | 330 |

Complete Leaderboard |

Given an array **arr[]** of integers of size **N** and a number **X**, the task is to find the sum of subarray having maximum sum less than or equal to the given value of **X**.

**Example 1:**

**Input: **N = 5, X = 11
arr[] = {1, 2, 3, 4, 5}
**Output:** 10
**Explanation**: Subarray having maximum
sum is {1, 2, 3, 4}.

**Example 2:**

**Input: **N = 5, X = 7
arr[] = {2, 4, 6, 8, 10}
**Output:** 6
**Explanation:** Subarray having maximum
sum is {2, 4} or {6}.

**Your Task:**

This is a function problem. You don't need to take any input, as it is already accomplished by the driver code. You just need to complete the function **calculateMaxSumLength**() that takes array **arr, **integer **N**, and integer** X **as parameters and returns maximum sum of any subarray that is less than or equal to x.

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

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

**Constraints:**

1 ≤ N ≤ 10^{6}

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?

Yes
Maximum sum of subarray less than or equal to x

...