FastPrepConsecutive Sum
Problems/Consecutive Sum

Consecutive Sum

Airbnb logoAirbnb● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem was in a set of past Airbnb practice questions. A candidate saw the set alongside their own Airbnb software engineer intern online assessment in October 2021 and shared it. The task is to count the ways a number can be written as a sum of two or more consecutive positive integers.

The set gave the full task, the limit and two samples plus a worked example, so nothing had to be filled in.

Our version is about 99% the same as the reported question.

You are given a positive whole number num.

Count the ways to write num as a sum of two or more consecutive positive integers, such as 4 + 5 + 6. Two ways are different if they use a different run of numbers.

Return the number of ways.

Function

consecutive(num: long) → int

Examples

Example 1

num = 21return = 3

There are three ways: 1 + 2 + 3 + 4 + 5 + 6 = 21, 6 + 7 + 8 = 21 and 10 + 11 = 21.

Example 2

num = 15return = 3

There are three ways: 1 + 2 + 3 + 4 + 5 = 15, 4 + 5 + 6 = 15 and 7 + 8 = 15.

Example 3

num = 10return = 1

The only way is 1 + 2 + 3 + 4 = 10. No run of two or three numbers adds up to 10.

Constraints

  • 1 <= num <= 1012

More Airbnb Online Assessment questions

  • Task Management SystemOA · Seen Nov 2026
  • Recipe Management SystemOA · Seen Nov 2026
  • Progressive Banking SystemOA · Seen Nov 2026
  • Credit Accounts with Scheduled TransfersOA · Seen Oct 2026
  • Parcel Attribute Store with TTLOA · Seen Oct 2026
  • Parcel Event TrackingOA · Seen Oct 2026
  • Median Home Price by CityOA · Seen Sep 2026
  • In-Memory File SystemOA · Seen Sep 2026
  • Worker Management (Promotion Track), Part 4: Full-Shift Double PayOA · Seen Sep 2026
  • Worker Management (Promotion Track), Part 3: Promotions and SalaryOA · Seen Sep 2026

Similar questions at other companies

  • Last Object Exit TimeIBM · OAIBM interview questions
  • Count Prime Values in SubtreesVisa · OAVisa interview questions
  • Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
  • Server Upgrade PlanningWells Fargo · OAWells Fargo interview questions
  • Capping Portfolio WeightsCapstone Investment Advisors · OA
  • Gaussian Naive Bayes Classifier (Machine Learning OA)Pinterest · OAPinterest interview questions
  • Bold Play to Reach a GoalSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
  • Repeated Mirror XORMathWorks · OAMathWorks interview questions
  • Count Lucky TicketsThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions

Interview reports that mention this question

  • Airbnb Intern OA and Onsite Rounds: 16 Experiences (Part 5 of 7)

Airbnb interview experiences

  • Airbnb SWE OA: Four-Level Banking System: 1 Experience
  • Airbnb Campus and Full-Time SWE OA / Interviews: 9 Experiences
  • Airbnb Intern Phone Interviews: 21 Experiences (Part 7 of 7)
  • Airbnb Intern OA and Phone Screens: 17 Experiences (Part 6 of 7)
  • Airbnb Intern OA, Diplomacy Game: 19 Experiences (Part 4 of 7)
All Airbnb interview questionsSee Airbnb hiring insights
Saved
class Solution {
    public int consecutive(long num) {
      // Write your code here.
    }
}
Checking account…