Question: Say you are given `A` oranges and `B` apples. You want to create a basket of total `N` fruits. What is the total number of combination of apples and oranges you can make?  

Assuming `A+B >= N`.

**Example:**  

I have 6 oranges and 6 apples and I want to create a basket with total 9 fruits.  

So I have 4 different combinations:

```
3 apples 6 oranges
4 apples 5 oranges
5 apples 4 oranges
6 apples 3 oranges

```

I want to create a simple (and efficient) algorithm to calculate this number.  

Is there any mathematical / combinatoric way to calculate this number in O(1)? I couldn't find a correct formula for this.

Answer: 
Lets say `A_max` is the maximum of number of `A` that can be included in the combination, and `A_min` be the least number of `A` that must be included in any combination. Then there will be two conditions that must be satisified:

1. `A_max + B_min = N`
2. `A_min + B_max = N`

Since we know `A_max`(which is `min(NumOfA, N)`), `B_min` can be found easily from first equation. Similarly one can find `A_min` from second equation.
Consequently, the list of combinations would be:

`A_max + B_min`

`(A_max-1) + (B_min+1)`

`(A_max-2) + (B_min+2)`

...

`(A_min) + (B_max)`

So the count of such combinations would be `(A_max - A_min + 1)` or `(B_max - B_min + 1)`
It should be

```
   ans = (A + B) - N + 1

```