Skip to content

Practice Greatest Sum Divisible by Three

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1262
LeetCode Problem

Greatest Sum Divisible by Three

Problem Statement

Given an integer array nums, return the maximum possible sum of elements of the array such that it is divisible by three.

Source: Greatest Sum Divisible by Three on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [3,6,5,1,8]
Output
18

# Example 2

Input
nums = [4]
Output
0

# Example 3

Input
nums = [1,2,3,4,4]
Output
12

Constraints

1 <= nums.length <= 4 * 10^4
1 <= nums[i] <= 10^4

Related LeetCode Problems

Practice more problems similar to Greatest Sum Divisible by Three.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.