`{"id":"7e6be171-e3d9-4ad2-9174-cf5330944875","name":"Print Zigzag","description":"1. Here are a few sets of inputs and outputs for your reference\r\nInput1 -> 1\r\nOutput1 -> 1 1 1\r\n\r\nInput2 -> 2\r\nOutput2 -> 2 1 1 1 2 1 1 1 2\r\n\r\nInput2 -> 3\r\nOutput3 -> 3 2 1 1 1 2 1 1 1 2 3 2 1 1 1 2 1 1 1 2 3\r\n\r\n2. Figure out the pattern and complete the recursive function pzz to achieve the above for any positive number n.\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":"As discussed in point 1 of description","constraints":"1 &lt;= n &lt;= 10","sampleCode":{"cpp":{"code":"#include<iostream>\r\nusing namespace std;\r\n\r\n\r\nvoid pzz(int n){\r\n // write your code here\r\n \r\n}\r\n\r\n\r\n\r\nint main(){\r\n int n; cin>>n;\r\n pzz(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 pzz(int n){\r\n \r\n }\r\n\r\n}"},"python":{"code":"def printZigZag(n):\n # write your code here\n\nnum = int(input())\nprintZigZag(num)"}},"points":10,"difficulty":"easy","sampleInput":"3","sampleOutput":"3 2 1 1 1 2 1 1 1 2 3 2 1 1 1 2 1 1 1 2 3","questionVideo":"https://www.youtube.com/embed/R7qja_gZrvI","hints":[],"associated":[{"id":"03720599-e532-4cbb-acd7-b459026ca602","name":"(Print zigZag) What is the output when n=4?","slug":"print-zigzag-what-is-the-output-when-n-4","type":4},{"id":"d3bd5ebf-84ac-4694-8383-fb8e57de10c0","name":"(Print zigZag) Can this problem be solved without using LIFO?","slug":"print-zigzag-can-this-problem-be-solved-without-using-lifo","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":"34355369-9d95-49c8-81a9-36c5c9877701","name":"Print Zigzag","slug":"print-zigzag","type":1}],"next":{"id":"ae000485-c119-4155-9b89-7fdfcaa1f489","name":"Print Zigzag","type":3,"slug":"print-zigzag"},"prev":{"id":"bcbf6880-0490-4ef8-8036-8c3a2d3270ed","name":"Power Function","type":3,"slug":"power-function"}}}`

# Print Zigzag

1. Here are a few sets of inputs and outputs for your reference Input1 -> 1 Output1 -> 1 1 1 Input2 -> 2 Output2 -> 2 1 1 1 2 1 1 1 2 Input2 -> 3 Output3 -> 3 2 1 1 1 2 1 1 1 2 3 2 1 1 1 2 1 1 1 2 3 2. Figure out the pattern and complete the recursive function pzz to achieve the above for any positive number n. 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":"7e6be171-e3d9-4ad2-9174-cf5330944875","name":"Print Zigzag","description":"1. Here are a few sets of inputs and outputs for your reference\r\nInput1 -> 1\r\nOutput1 -> 1 1 1\r\n\r\nInput2 -> 2\r\nOutput2 -> 2 1 1 1 2 1 1 1 2\r\n\r\nInput2 -> 3\r\nOutput3 -> 3 2 1 1 1 2 1 1 1 2 3 2 1 1 1 2 1 1 1 2 3\r\n\r\n2. Figure out the pattern and complete the recursive function pzz to achieve the above for any positive number n.\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":"As discussed in point 1 of description","constraints":"1 &lt;= n &lt;= 10","sampleCode":{"cpp":{"code":"#include<iostream>\r\nusing namespace std;\r\n\r\n\r\nvoid pzz(int n){\r\n // write your code here\r\n \r\n}\r\n\r\n\r\n\r\nint main(){\r\n int n; cin>>n;\r\n pzz(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 pzz(int n){\r\n \r\n }\r\n\r\n}"},"python":{"code":"def printZigZag(n):\n # write your code here\n\nnum = int(input())\nprintZigZag(num)"}},"points":10,"difficulty":"easy","sampleInput":"3","sampleOutput":"3 2 1 1 1 2 1 1 1 2 3 2 1 1 1 2 1 1 1 2 3","questionVideo":"https://www.youtube.com/embed/R7qja_gZrvI","hints":[],"associated":[{"id":"03720599-e532-4cbb-acd7-b459026ca602","name":"(Print zigZag) What is the output when n=4?","slug":"print-zigzag-what-is-the-output-when-n-4","type":4},{"id":"d3bd5ebf-84ac-4694-8383-fb8e57de10c0","name":"(Print zigZag) Can this problem be solved without using LIFO?","slug":"print-zigzag-can-this-problem-be-solved-without-using-lifo","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":"34355369-9d95-49c8-81a9-36c5c9877701","name":"Print Zigzag","slug":"print-zigzag","type":1}],"next":{"id":"ae000485-c119-4155-9b89-7fdfcaa1f489","name":"Print Zigzag","type":3,"slug":"print-zigzag"},"prev":{"id":"bcbf6880-0490-4ef8-8036-8c3a2d3270ed","name":"Power Function","type":3,"slug":"power-function"}}}`

Editor

# Print Zigzag

easy

1. Here are a few sets of inputs and outputs for your reference Input1 -> 1 Output1 -> 1 1 1 Input2 -> 2 Output2 -> 2 1 1 1 2 1 1 1 2 Input2 -> 3 Output3 -> 3 2 1 1 1 2 1 1 1 2 3 2 1 1 1 2 1 1 1 2 3 2. Figure out the pattern and complete the recursive function pzz to achieve the above for any positive number n. 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 <= 10

## Format

A number n

### Output

As discussed in point 1 of description

## 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 1 2 1 1 1 2 3 2 1 1 1 2 1 1 1 2 3`

Question Video

Discussions

Show Discussion

Related Resources