Print Series Problem Statement
Given two positive integers N
and K
, your task is to generate a series of numbers by subtracting K
from N
until the result is 0 or negative, then adding K
back until it reaches N
again. This must be achieved without using any loops.
Example:
Input:
N = 5, K = 2
Output:
[5, 3, 1, -1, 1, 3, 5]
Input:
The first line contains an integer T
, representing the number of test cases.
Each of the followingT
lines contains two space-separated integersN
andK
.
Output:
For each test case, output a single line containing the series.
Constraints:
1 <= T <= 100
1 <= N <= 3000
1 <= K <= N
- Time Limit: 1 second
Note:
You do not need to print anything; it has already been handled. Just implement the function to return the series.
Be the first one to answer
Add answer anonymously...
Top MAQ Software Software Engineer interview questions & answers
Popular interview questions of Software Engineer
Top HR questions asked in MAQ Software Software Engineer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app