This kata's sensei hasn't been around since february 2018. Little chance this kata will ever be approved I guess.
Great kata that deserves more solutions. Thanks for creating it.
This solution is exactly the same solution as the reference solution, even the comments are the same. This must be a very big coincidence ...
Only //what? is added to not get a copy solution.
More equal solutions ...
This one and this one.
E W N S N N N E W S N
E W == 0
N S == 0
E W == 0
S N == 0
N N N
By eleminating E W and S N combinations N N N remains. Nothing wrong with this kata.
Great kata. Listen to this while finding a solution.
Real life coding challenges are defined whith less clear requirements most of the time.
It is even possible to extend this by thinking that 18 is odder than 24.
Take a closer look at your loop declaration.
for (int i = 0; i > 5; i++)
No wonder that your beans! are missing from the log I guess. (> != <)
Please read the earlier comments in this thread. You will see that you are not the only one having problems to solve this kata. Simply looping through the list is too slow. Try to search for articles about datastructures that can sort or search arrays very efficiently and you will find what you need.
Java translation is ready for review.
Your seventh column has two ones, and your eighth column has two eights. So, I'm sorry to say, but your answer is wrong.
In the Haskell Sample Test "should perform many-to-many JOIN and apply WHERE" a comparison without spaces is present. The EBNF-scheme therefor is not exactly correct, but imho this is not a big problem.
In your code you effectively change the input array trips. You can find that out if you do a console.log(trips) just before you return your result. If you don't change the input array, your answer will be accepted.
I think I found the problem. In your code is the line item++ . This effectively changes the trips array in such a way that only trips of zero days remain.
You can solve this by placing var x = item in front of your while loop and replace every occurrence of item with x.
var x = item
To check this do a console.log(trips) just before you return your answer.
This was also reported by jlb071 in an earlier post.
More or less it means that the consumed execution time of your program grows quadratically with the size of your input. If an algorithm has time complexity O(n), the execution time grows linear with respect to the size of your input. A start page for further investigation is this one, but there are a zillion more.
If you have an array with n elements and you visit each element n-times you have an algorithm O(n^2) and that is less efficient than visiting each element only once (O(n)).
In the second example:
n = 4, k = 2 => [(1,4,2,3), (2,1,4,3), (3,1,2,4), (1,3,4,2), (2,3,4,1)] => 5
the last tuple (2,3,4,1) should have two inversions. I see three, i.e. (2,1), (3,1) and (4,1).
Shouldn't the last one be (2,3,1,4)?