k
using the quadratic equation k = min(n, int((-1 + sqrt(1 + 8 * maxSum)) / 2))
.currentSum
to k * (k + 1) / 2
and count
to k
.bannedSet
from the banned
array.bannedSet
and for each banned number b
that is less than or equal to k
, subtract b
from currentSum
and decrement count
.k + 1
to n
and for each non-banned number, add it to currentSum
and increment count
until currentSum
exceeds maxSum
.count
.