For an integer array nums, an inverse pair is a pair of integers (i, j) where 0 <= i < j < nums.length and nums(i) > nums(j).

Given two integers n and k, return the number of different arrays consist of numbers from 1 to n such that there are exactly k inverse pairs. Since the answer can be huge, return it modulo 10^9 + 7.

https://leetcode.com/problems/k-inverse-pairs-array/solution/

Brute Force Solution:

```
from itertools import permutations, combinations
class Solution:
def kInversePairs(self, n: int, k: int) -> int:
array = (x for x in range(1,n+1))
array_permutations = list(permutations(array))
memoized = {}
count = 0
for each_permutation in array_permutations:
each_permutation = list(each_permutation)
if self.has_exactly_k_inverse_pair(k, each_permutation, memoized):
count += 1
return count % 1000000007
def has_exactly_k_inverse_pair(self, k, array, memoized):
count = 0
list_of_sequential_pairs = combinations(array, 2)
for item_i, item_j in list_of_sequential_pairs:
cached = memoized.get((item_i, item_j), None)
if not cached:
result = self.is_inverse_pair((item_i, item_j))
if result:
memoized((item_i, item_j)) = result
count += 1
else:
count += 1
if count > k:
return False
return count == k
def is_inverse_pair(self, tup):
return tup(0) > tup(1)
```

I am looking for code review just for the brute force solutions. I am looking too get constructive feedback mainly with:

- Using
`memoized`

dictionary for storing`True`

entries only. - Being able to pass memoized and update it
- Using tuples as keys in python
- Overall best coding practices.