-2
Ex :- Input: n = 12, k = 5
Output: ans = 2
Sorted list S: ["1", "10", "11", "12", "2", "3", "4", "5", ...., "9"] ans = 2
-2
Ex :- Input: n = 12, k = 5
Output: ans = 2
Sorted list S: ["1", "10", "11", "12", "2", "3", "4", "5", ...., "9"] ans = 2
1
(n,i)=>+[...Array(n).keys()].map(x=>x+1+"").sort()[i-1]
Unfortunately I can't comment yet, so I'll include it in my answer:
Welcome to PPCG! To make this a challenge you have to clarify some requirements of the challenge. Add a proper description, define the expected output and the winning criteria and also add some example tests.
The default sort in javascript is lexicographic. So you can write .sort()
instead of .sort((a,b)=>a.localeCompare(b))
– Spitemaster – 2018-12-12T13:29:23.123
@Spitemaster well, yea. Not sure why I didn't think of that. Thanks :) – zruF – 2018-12-12T13:37:39.187
0
Welcome to PPCG! This site is for recreational programming puzzles, not programming help. If you intend this as a proper challenge, you'll have to add a objective winning criteria (e.g. [tag:code-golf]) , remove the [tag:c++] tag and make it sound a lot less like "I want help with my homework" – Jo King – 2018-12-12T10:22:00.430
I think that this could be a good question for code-golf, provided that it isn't a duplicate. There are two remarks however, and both of them are that index-related. Since you say that you use C++ (which is 0-indexed), why are your numbers 1-12 rather than 0-11, and why is the answer
a[4]
if5
is the input? Also,╒░s\(§
and╒░s§
are solutions in MathGolf for the original problem and a 0-indexed version. – maxb – 2018-12-12T13:10:52.960