Hackerrank – Picking Cards

Problem Statement
A description of the problem can be found on Hackerrank.

Solution
Sort the array descending. Take N from the input.
For each element e substract N - e. That means that there is only N - e combinations to choose these two cards. After substraction decrement N and select the next element. All card combinations are multiplication of all N - e substractions. If at least N - e is lower than 0 the result is automatically 0. Don’t forget modulo 1 000 000 007.

I created solution in:

All solutions are also available on my GitHub.

Java

JavaScript

Scala

Ruby