Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
really clever
The input array will always be valid! (odd-length >= 3)
The solution seems simpler and i was wondering why it isn't voted as a best practice. Your comment made light. Thank you.
Sorting increases execution time. Even for a 7 element array.
exactly
Sort is overkill here. IMO too much upvotes.
Yes it is
Yup, that's the math way to do it.
Hello, thank you for your answer.
I just saw the example tests:
names1 = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
r1 = 1
res1 = "Sheldon"
names2 = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
r2 = 6
res2 = "Howard"
names3 = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
r3 = 10
res3 = "Penny"
Test.assertEquals(whoIsNext(names1, r1), res1)
Test.assertEquals(whoIsNext(names2, r2), res2)
Test.assertEquals(whoIsNext(names3, r3), res3)
Your ruby and java version have r=6 , res=Sheldon indeed, maybe it's a cache thing or something because it has been a while since I've tried to solve it.
I see a test where r=6 and the answer is Sheldon, as expected. Not sure where you are seeing what you are seeing. I solved in JavaScript, maybe there is an error in a different language.
In descritption we see:
"The input data consist of an array which contains five names, and single integer n.
(1 ≤ n ≤ 1 000 000 000)."
But in output/examples we must receive "Leonard" for n == 7 230 702 951.
How can it be possible?
This comment is hidden because it contains spoiler information about the solution