FastPrepCount Targets Formed by K Consecutive Positive Integers
Problems/Count Targets Formed by K Consecutive Positive Integers

Count Targets Formed by K Consecutive Positive Integers

Arm logoArm● MediumNEW GRADOA

Updated Aug 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The inclusive range, K consecutive positive integers, sum formula, divisibility observation, and count result are source-backed. Numeric bounds are practice constraints; match confidence is about 98%.

Given an inclusive target range [start, end] and a positive integer k, count the targets in the range that can be written as the sum of exactly k consecutive positive integers.

For example, a valid target has the form x + (x + 1) + ... + (x + k - 1) for some integer x >= 1.

Function

countConsecutiveSumTargets(start: long, end: long, k: int) → long

Examples

Example 1

start = 1end = 20k = 3return = 5

The valid sums are 6, 9, 12, 15, and 18.

Example 2

start = 10end = 30k = 2return = 10

The odd targets 11 through 29 are sums of two consecutive positive integers.

Example 3

start = 1end = 5k = 4return = 0

The smallest four-term positive sum is 10, outside the range.

Constraints

  • 1 <= start <= end <= 10^18
  • 1 <= k <= 10^9

More Arm interview questions

  • Triple-Position Alphabet EncodingOA · Seen Aug 2026
  • Power of Two Without DivisionPHONE SCREEN · Seen Nov 2021

Similar questions at other companies

  • Bold Play to Reach a GoalSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Chance a Die Game Balance Reaches ZeroOptiver · OAOptiver interview questions
  • Maximum Score with Prime JumpsMicrosoft · OAMicrosoft interview questions
  • Sliding-Window Means with IEEE Special ValuesHeadlands Technologies · OAHeadlands Technologies interview questions
  • Count Distinct Arrays After Decrement OperationsBloomberg LP · OABloomberg LP interview questions
  • Polynomial CoefficientsShopify · OAShopify interview questions
  • Basic Calculator IITypeSafe AI · OA
  • Last Object to Fall Off the TableConfluent · OAConfluent interview questions
  • Last Object Exit TimeIBM · OAIBM interview questions
  • Count Prime Values in SubtreesVisa · OAVisa interview questions
See Arm hiring insights
Saved
class Solution {
    public long countConsecutiveSumTargets(long start, long end, int k) {
        // Write your solution here.
    }
}
Checking account…