`{"id":"8273abb1-d22a-45c5-b447-3d8af36ec683","name":"Print Increasing Decreasing","description":"1. You are given a positive number n. \r\n2. You are required to print the counting from n to 1 and back to n again.\r\n3. You are required to not use any loops. Complete the body of pdi function to achieve it. Don't change the signature of the function.\r\n\r\nNote -> The online judge can't force you to write the function recursively but that is what the spirit of question is.Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.","inputFormat":"A number n","outputFormat":"n\r\nn - 1\r\nn - 2\r\n..\r\n1\r\n1\r\n2\r\n3\r\n..\r\nn","constraints":"1 &lt;= n &lt;= 1000","sampleCode":{"cpp":{"code":"#include<iostream>\r\nusing namespace std;\r\n\r\nvoid printIncDec(int n){\r\n // write your code here\r\n \r\n}\r\n\r\n\r\nint main(){\r\n int n; cin>>n;\r\n printIncDec(n);\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n public static void pdi(int n){\r\n \r\n }\r\n\r\n}"},"python":{"code":"def printIncDec(n):\n # write your code here\n\nn = int(input())\nprintIncDec(n)"}},"points":10,"difficulty":"easy","sampleInput":"3","sampleOutput":"3\r\n2\r\n1\r\n1\r\n2\r\n3","questionVideo":"https://www.youtube.com/embed/V-WSKmGTWxk","hints":[],"associated":[{"id":"10016f1a-8af4-44d2-96c3-01d884b1eeda","name":"(Print Increasing Decreasing) What will be the time complexity of this problem?","slug":"print-increasing-decreasing-what-will-be-the-time-complexity-of-this-problem","type":4},{"id":"3c3f92b2-c4b4-470e-8a6b-6aa7e9951945","name":"(Print Increasing Decreasing) What will be the output for n=4?","slug":"print-increasing-decreasing-what-will-be-the-output-for-n-4","type":4},{"id":"884f3c87-8870-48fc-8b56-11bf3f7fc9db","name":"(Print Increasing Decreasing) How many recursive call do we make in this question?","slug":"print-increasing-decreasing-how-many-recursive-call-do-we-make-in-this-question","type":4},{"id":"d675ce1d-0774-4a0f-95b0-03d697fad9be","name":"(Print Increasing Decreasing) What will be the base condition?","slug":"print-increasing-decreasing-what-will-be-the-base-condition","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"d341a7c9-1269-409c-b851-0bb512289544","name":"Recursion And Backtracking For Beginners","slug":"recursion-and-backtracking-for-beginners","type":0},{"id":"c2dbff03-98ef-484f-b8ee-63a11007619c","name":"Print Increasing Decreasing","slug":"print-increasing-decreasing","type":1}],"next":{"id":"59400822-c4b4-45d7-a9f5-366fcd00b86c","name":"Print Increasing Decreasing","type":3,"slug":"print-increasing-decreasing"},"prev":{"id":"dee28cf8-30a1-4f11-b618-39cd553d96dc","name":"Print Increasing","type":3,"slug":"print-increasing"}}}`

Print Increasing Decreasing

1. You are given a positive number n. 2. You are required to print the counting from n to 1 and back to n again. 3. You are required to not use any loops. Complete the body of pdi function to achieve it. Don't change the signature of the function. Note -> The online judge can't force you to write the function recursively but that is what the spirit of question is.Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.

`{"id":"8273abb1-d22a-45c5-b447-3d8af36ec683","name":"Print Increasing Decreasing","description":"1. You are given a positive number n. \r\n2. You are required to print the counting from n to 1 and back to n again.\r\n3. You are required to not use any loops. Complete the body of pdi function to achieve it. Don't change the signature of the function.\r\n\r\nNote -> The online judge can't force you to write the function recursively but that is what the spirit of question is.Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.","inputFormat":"A number n","outputFormat":"n\r\nn - 1\r\nn - 2\r\n..\r\n1\r\n1\r\n2\r\n3\r\n..\r\nn","constraints":"1 &lt;= n &lt;= 1000","sampleCode":{"cpp":{"code":"#include<iostream>\r\nusing namespace std;\r\n\r\nvoid printIncDec(int n){\r\n // write your code here\r\n \r\n}\r\n\r\n\r\nint main(){\r\n int n; cin>>n;\r\n printIncDec(n);\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n public static void pdi(int n){\r\n \r\n }\r\n\r\n}"},"python":{"code":"def printIncDec(n):\n # write your code here\n\nn = int(input())\nprintIncDec(n)"}},"points":10,"difficulty":"easy","sampleInput":"3","sampleOutput":"3\r\n2\r\n1\r\n1\r\n2\r\n3","questionVideo":"https://www.youtube.com/embed/V-WSKmGTWxk","hints":[],"associated":[{"id":"10016f1a-8af4-44d2-96c3-01d884b1eeda","name":"(Print Increasing Decreasing) What will be the time complexity of this problem?","slug":"print-increasing-decreasing-what-will-be-the-time-complexity-of-this-problem","type":4},{"id":"3c3f92b2-c4b4-470e-8a6b-6aa7e9951945","name":"(Print Increasing Decreasing) What will be the output for n=4?","slug":"print-increasing-decreasing-what-will-be-the-output-for-n-4","type":4},{"id":"884f3c87-8870-48fc-8b56-11bf3f7fc9db","name":"(Print Increasing Decreasing) How many recursive call do we make in this question?","slug":"print-increasing-decreasing-how-many-recursive-call-do-we-make-in-this-question","type":4},{"id":"d675ce1d-0774-4a0f-95b0-03d697fad9be","name":"(Print Increasing Decreasing) What will be the base condition?","slug":"print-increasing-decreasing-what-will-be-the-base-condition","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"d341a7c9-1269-409c-b851-0bb512289544","name":"Recursion And Backtracking For Beginners","slug":"recursion-and-backtracking-for-beginners","type":0},{"id":"c2dbff03-98ef-484f-b8ee-63a11007619c","name":"Print Increasing Decreasing","slug":"print-increasing-decreasing","type":1}],"next":{"id":"59400822-c4b4-45d7-a9f5-366fcd00b86c","name":"Print Increasing Decreasing","type":3,"slug":"print-increasing-decreasing"},"prev":{"id":"dee28cf8-30a1-4f11-b618-39cd553d96dc","name":"Print Increasing","type":3,"slug":"print-increasing"}}}`

Editor

Print Increasing Decreasing

easy

1. You are given a positive number n. 2. You are required to print the counting from n to 1 and back to n again. 3. You are required to not use any loops. Complete the body of pdi function to achieve it. Don't change the signature of the function. Note -> The online judge can't force you to write the function recursively but that is what the spirit of question is.Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.

1 <= n <= 1000

Format

A number n

Output

n n - 1 n - 2 .. 1 1 2 3 .. n

Example

Sample Input

`.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}3`

Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}3 2 1 1 2 3```

Question Video

Discussions

Show Discussion

Related Resources