Array ( [0] => [1] => questions [2] => HackwithInfy-Previous-Questions [3] => Prime-seiving )
Login to see Discussion
Step-i)create array of size n
Step-ii) initialize the array with true
Step-iii) initialize i to 2
Step-iv) if element at index i is true then value at index equal to multiples of i change to false
Step-v) increment i by one value
Step-vi) repeat steps iv and v till i*i is less than the given number
Step-vii) create a empty string answer
Step-viii) append all the index whose value is true
Step-ix) return the string
Time Complexity: (nloglogn)
Space Complexity:
Note :
Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.
Login to see Solution