Created
September 25, 2016 22:54
-
-
Save stsatlantis/95699c4324bacb550c036da99ddf57b3 to your computer and use it in GitHub Desktop.
Given integers n, l and r, find the number of ways to represent n as a sum of two integers A and B such that l ≤ A ≤ B ≤ r.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def countSumOfTwoRepresentations2(n: Int, l: Int, r: Int): Int = { | |
if(l > n/2) 0 else math.min(n/2 - l, r - n/2) + (if(n%2 == 1) 0 else 1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment