https://github.com/prakhar-002/leetcode
π LeetCode Solution Hub π₯ | Get all solutions π§© for daily challenges and specific tasks πͺπ» | Example: π¨ LeetCode 75 - πͺ» Ace Coding Interview, π¦ SQL 50 - π½ Crack SQL Interview, π 30 Days of JavaScript - π» Learn JS Basics
https://github.com/prakhar-002/leetcode
c cpp java javascript leet leetcode leetcode-cpp leetcode-java leetcode-javascript leetcode-practice leetcode-python leetcode-solutions python3 questions-and-answers
Last synced: 17 days ago
JSON representation
π LeetCode Solution Hub π₯ | Get all solutions π§© for daily challenges and specific tasks πͺπ» | Example: π¨ LeetCode 75 - πͺ» Ace Coding Interview, π¦ SQL 50 - π½ Crack SQL Interview, π 30 Days of JavaScript - π» Learn JS Basics
- Host: GitHub
- URL: https://github.com/prakhar-002/leetcode
- Owner: Prakhar-002
- Created: 2024-05-24T09:01:02.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-16T04:25:18.000Z (19 days ago)
- Last Synced: 2025-06-16T05:27:23.245Z (19 days ago)
- Topics: c, cpp, java, javascript, leet, leetcode, leetcode-cpp, leetcode-java, leetcode-javascript, leetcode-practice, leetcode-python, leetcode-solutions, python3, questions-and-answers
- Language: Java
- Homepage: https://leetcode.com/u/Prakhar-002/
- Size: 3.75 MB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 689. Maximum Sum of 3 Non-Overlapping Subarrays
β₯ β’οΈ 689 Leetcode Medium β’οΈ
# Description π ΛΒ°β’*ββ·
### Given an integer array `nums` and an integer `k`, find three non-overlapping subarrays of length `k` with maximum sum and return them.
### Return the result as a list of indices representing the starting position of each interval (0-indexed). If there are multiple answers, return the lexicographically smallest one.
# Example π‘ 1οΈβ£ ΛΒ°β’*ββ·
### π₯ `Input` β€ nums = [1,2,1,2,6,7,5,1], k = 2
### π€ `Output` β€ [0,3,5]
### π¦ `Explanation` β€ Subarrays [1, 2], [2, 6], [7, 5] correspond to the starting indices [0, 3, 5]. We could have also taken [2, 1], but an answer of [1, 3, 5] would be lexicographically larger.
# Example π‘ 2οΈβ£ ΛΒ°β’*ββ·
### π₯ `Input` β€ nums = [1,2,1,2,1,2,1,2,1], k = 2
### π€ `Output` β€ [0,2,4]
# Constraints π ΛΒ°β’*ββ·
πΉ **1 <= nums.length <= 2 * 104**
πΉ **1 <= nums[i] < 216**
πΉ **`1 <= k <= floor(nums.length / 3)`**
# Topics π ΛΒ°β’*ββ·
πΈ **Array**
πΈ **Dynamic Programming**# Solution βοΈ ΛΒ°β’*ββ·
| π Language π | πͺΆ Solution πͺΆ |
| ------------- | ------------- |
|  | [JAVAπ](https://github.com/Prakhar-002/LEETCODE/blob/main/%F0%9F%93%9C%20Daily%20Challange%20%F0%9F%92%A1/12%20December%20%F0%9F%90%BB%E2%80%8D%E2%9D%84%EF%B8%8F%202024/28%20-%2012%20-%202024%20---%20689.%20Maximum%20Sum%20of%203%20Non-Overlapping%20Subarrays%20%E2%98%83%EF%B8%8F%20%F0%9F%8D%81%20%F0%9F%8D%B0%20%F0%9F%8E%B2/%F0%9F%8D%81JAVA%20-%20689.%20Maximum%20Sum%20of%203%20Non-Overlapping%20Subarrays.java) |
|  | [C++π²](https://github.com/Prakhar-002/LEETCODE/blob/main/%F0%9F%93%9C%20Daily%20Challange%20%F0%9F%92%A1/12%20December%20%F0%9F%90%BB%E2%80%8D%E2%9D%84%EF%B8%8F%202024/28%20-%2012%20-%202024%20---%20689.%20Maximum%20Sum%20of%203%20Non-Overlapping%20Subarrays%20%E2%98%83%EF%B8%8F%20%F0%9F%8D%81%20%F0%9F%8D%B0%20%F0%9F%8E%B2/%F0%9F%8E%B2CPP%20-%20689.%20Maximum%20Sum%20of%203%20Non-Overlapping%20Subarrays.cpp) |
|  | [PYTHONπ°](https://github.com/Prakhar-002/LEETCODE/blob/main/%F0%9F%93%9C%20Daily%20Challange%20%F0%9F%92%A1/12%20December%20%F0%9F%90%BB%E2%80%8D%E2%9D%84%EF%B8%8F%202024/28%20-%2012%20-%202024%20---%20689.%20Maximum%20Sum%20of%203%20Non-Overlapping%20Subarrays%20%E2%98%83%EF%B8%8F%20%F0%9F%8D%81%20%F0%9F%8D%B0%20%F0%9F%8E%B2/%F0%9F%8D%B0PYTHON%20-%20689.%20Maximum%20Sum%20of%203%20Non-Overlapping%20Subarrays.py) |
|  | [JAVASCRIPTβοΈ](https://github.com/Prakhar-002/LEETCODE/blob/main/%F0%9F%93%9C%20Daily%20Challange%20%F0%9F%92%A1/12%20December%20%F0%9F%90%BB%E2%80%8D%E2%9D%84%EF%B8%8F%202024/28%20-%2012%20-%202024%20---%20689.%20Maximum%20Sum%20of%203%20Non-Overlapping%20Subarrays%20%E2%98%83%EF%B8%8F%20%F0%9F%8D%81%20%F0%9F%8D%B0%20%F0%9F%8E%B2/%E2%98%83%EF%B8%8FJAVASCRIPT%20-%20689.%20Maximum%20Sum%20of%203%20Non-Overlapping%20Subarrays.js) |