FastPrepFind Consecutive Integer Sequences
Problems/Find Consecutive Integer Sequences

Find Consecutive Integer Sequences

IDFC Bank logoIDFC Bank● EasyFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Given a positive integer n, find every sequence of consecutive positive integers whose sum is equal to n.

Each multi-number sequence must contain at least two numbers. Include the single-number sequence [n] as the final sequence so the total number of returned sequences matches the total count requested by the source prompt.

Return the sequences in increasing order of their first value. Represent each sequence as a string whose numbers are joined by " + ".

Function

findConsecutiveIntegerSequences(n: int) → String[]

Examples

Example 1

n = 15return = ["1 + 2 + 3 + 4 + 5","4 + 5 + 6","7 + 8","15"]

The consecutive positive-integer sequences that sum to 15 are 1 + 2 + 3 + 4 + 5, 4 + 5 + 6, and 7 + 8. The source prompt also includes the single-number sequence 15 in the total count.

Constraints

  • n is a positive integer.

More IDFC Bank problems

  • Employee Free TimeONSITE INTERVIEW · Seen Aug 2026
  • Minimum Cake CutsOA · Seen Jul 2026
  • Smallest Adjacent ConcatenationOA · Seen Jul 2026
All IDFC Bank interview questionsSee IDFC Bank hiring insights
Saved
class Solution {
    public String[] findConsecutiveIntegerSequences(int n) {
      // write your code here
    }
}
Checking account…