{"id":"7ae1db0a-6537-4812-90e5-2a6540ae12f1","name":"Lexicographical Numbers","description":"1. You are given a number.\r\n2. You have to print all the numbers from 1 to n in lexicographical order.\r\n\r\nNote -> Check out the question video and write the recursive code as it is intended without \r\n changing signature. The judge can't force you but intends you to teach a concept.","inputFormat":"A number","outputFormat":"Check the sample output and question video","constraints":"1 &lt;= n &lt;= 50000","sampleCode":{"cpp":{"code":"#include<iostream>\nusing namespace std;\n\t\n\tvoid dfs(int i,int n)\n\t{\n\t if(i>n)\n\t {\n\t return;\n\t }\n\t cout<<i<<endl;\n\t for(int j=0;j<10;j++)\n\t {\n\t dfs(10*i+j,n);\n\t }\n\t}\n\t\n\tint main()\n\t{\n\t int n;\n\t cin>>n;\n //write your code here\n\t\tfor(int i=1;i<=9;i++)\n\t\t{\n\t\t dfs(i,n);\n\t\t}\n\t}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\r\n\t\t//write your code here\r\n\t}\r\n\t\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"14","sampleOutput":"1\r\n10\r\n11\r\n12\r\n13\r\n14\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9","questionVideo":"https://www.youtube.com/embed/gRo86WqFYSE?start=0&end=262","hints":[],"associated":[],"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":"082986ae-d618-4a59-9ab3-6d79056679a4","name":"Recursion and Backtracking For Intermediate","slug":"recursion-and-backtracking-for-intermediate-330","type":0},{"id":"aae597bd-0eba-4b04-ae2a-50918e1d3dc7","name":"Lexicographical Numbers","slug":"lexicographical-numbers","type":1}],"next":{"id":"3a510807-2123-463a-acfd-339959f901e3","name":"Lexicographical numbers MCQ","type":0,"slug":"lexicographical-numbers-mcq"},"prev":{"id":"bc535edc-1716-4b8f-85a9-62e410de7976","name":"Josephus Problem","type":3,"slug":"josephus-problem"}}}

Lexicographical Numbers

1. You are given a number. 2. You have to print all the numbers from 1 to n in lexicographical order. Note -> Check out the question video and write the recursive code as it is intended without changing signature. The judge can't force you but intends you to teach a concept.

{"id":"7ae1db0a-6537-4812-90e5-2a6540ae12f1","name":"Lexicographical Numbers","description":"1. You are given a number.\r\n2. You have to print all the numbers from 1 to n in lexicographical order.\r\n\r\nNote -> Check out the question video and write the recursive code as it is intended without \r\n changing signature. The judge can't force you but intends you to teach a concept.","inputFormat":"A number","outputFormat":"Check the sample output and question video","constraints":"1 &lt;= n &lt;= 50000","sampleCode":{"cpp":{"code":"#include<iostream>\nusing namespace std;\n\t\n\tvoid dfs(int i,int n)\n\t{\n\t if(i>n)\n\t {\n\t return;\n\t }\n\t cout<<i<<endl;\n\t for(int j=0;j<10;j++)\n\t {\n\t dfs(10*i+j,n);\n\t }\n\t}\n\t\n\tint main()\n\t{\n\t int n;\n\t cin>>n;\n //write your code here\n\t\tfor(int i=1;i<=9;i++)\n\t\t{\n\t\t dfs(i,n);\n\t\t}\n\t}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\r\n\t\t//write your code here\r\n\t}\r\n\t\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"14","sampleOutput":"1\r\n10\r\n11\r\n12\r\n13\r\n14\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9","questionVideo":"https://www.youtube.com/embed/gRo86WqFYSE?start=0&end=262","hints":[],"associated":[],"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":"082986ae-d618-4a59-9ab3-6d79056679a4","name":"Recursion and Backtracking For Intermediate","slug":"recursion-and-backtracking-for-intermediate-330","type":0},{"id":"aae597bd-0eba-4b04-ae2a-50918e1d3dc7","name":"Lexicographical Numbers","slug":"lexicographical-numbers","type":1}],"next":{"id":"3a510807-2123-463a-acfd-339959f901e3","name":"Lexicographical numbers MCQ","type":0,"slug":"lexicographical-numbers-mcq"},"prev":{"id":"bc535edc-1716-4b8f-85a9-62e410de7976","name":"Josephus Problem","type":3,"slug":"josephus-problem"}}}
plane

Editor


Loading...

Lexicographical Numbers

medium

1. You are given a number. 2. You have to print all the numbers from 1 to n in lexicographical order. Note -> Check out the question video and write the recursive code as it is intended without changing signature. The judge can't force you but intends you to teach a concept.

Constraints

1 <= n <= 50000

Format

Input

A number

Output

Check the sample output and question video

Example

Sample Input

14

Sample Output

1 10 11 12 13 14 2 3 4 5 6 7 8 9

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode