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 following T lines contains two space-separated integers N and K.

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.

AnswerBot
4mo

Generate a series of numbers by subtracting K from N until 0 or negative, then adding K back to reach N without using loops.

  • Create a recursive function to generate the series.

  • Subtract K from N until N...read more

Help your peers!
Select
Add answer anonymously...

MAQ Software Software Engineer interview questions & answers

A Software Engineer was asked 10mo agoQ. Given a singly linked list, reverse the nodes of the linked list k at a time and...read more
A Software Engineer was asked 11mo agoQ. How does hashing help in identifying duplicate values?
A Software Engineer was asked Q. Given an array, reverse the order of its elements.

Popular interview questions of Software Engineer

A Software Engineer was asked 10mo agoQ1. Given a singly linked list, reverse the nodes of the linked list k at a time and...read more
A Software Engineer was asked 11mo agoQ2. How does hashing help in identifying duplicate values?
A Software Engineer was asked Q3. Given an array, reverse the order of its elements.
MAQ Software Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits