Find Sequences
Updated
Problem statement
Given a number n (1 <= n <= 1010), the task is to find all the possible sequences of successive positive integer numbers (p, p+1, ..., p+m) that satisfy the equation: n = p^2 + (p+1)2 + ... + (p+m)2.
Input
The input consists of a single integer n.
Output
The output is an array of strings consisting of two parts. The first element should display the total number of possible sequences, denoted as k. The following k elements should contain the descriptions of the sequences. Each element is a string starts with the count of numbers in the corresponding sequence, denoted as c, followed by c integers representing the successive positive integer numbers, separated by a space. These k elements should be ordered in descending order of C.
Function
findSequences(n: long) → String[]Examples
Example 1
n = 2030return = ["2", "4 21 22 23 24", "3 25 26 27"]An explanation based on EDUCATED GUESS:::
There are two sequences that satisfy the equation for n = 2030:
- The sequence starting with
p = 21and having4numbers:21, 22, 23, 24. The sum of their squares is21^2 + 22^2 + 23^2 + 24^2 = 2030. - The sequence starting with
p = 25and having3numbers:25, 26, 27. The sum of their squares is25^2 + 26^2 + 27^2 = 2030.
Therefore, the output is ["2", "4 21 22 23 24", "3 25 26 27"], with the total number of sequences 2 followed by the sequences in descending order of the count of numbers.
Constraints
🐻
More Trend Micro interview questions
Similar questions at other companies
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Bold Play to Reach a GoalSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Repeated Mirror XORMathWorks · OAMathWorks interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Find Total CostJP Morgan Chase · OAJP Morgan Chase interview questions
- Macaron Order PriceOpenAI · OAOpenAI interview questions
- Daily Settlement for Long and Short PositionsBelvedere Trading · OA
- Last Object Exit TimeIBM · OAIBM interview questions
- Debug the Risk-Limit QuoterMillennium · OAMillennium interview questions
- Prime Factor VisitationMaven Securities · OAMaven Securities interview questions