Lexicographical order

Posted: 23 Sep, 2020
Difficulty: Moderate


Try Problem

You are given a positive integer N. Your task is to return a list of integers containing integers from 1 to N (both inclusive) in lexicographically ascending order.

For example:- Given 3 numbers 1, 3 and 10, the lexicographical ascending order will be 1, 10 and 3.

Input format:
The first and only line of input contains a single integer N.
Output format:
The only line of output contains N single space-separated integers i.e integers from 1 to N in lexicographical order.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= N <=10^6

Time Limit: 1 sec
Approach 1
  1. Initialize a list of strings and add numbers from 1 to N in it.
  2. Now, all we need to do is sort the list and return it
Try Problem