Python: display subarray divisible by k , how do I solve with hashtable?
<p>I am looking for <strong>Python</strong> solution</p>

<p>For example, For A=[2, -3, 5, 4, 3, -1, 7]. The for k = 3 there is a subarray for example {-3, 5, 4}. For, k=5 there is subarray {-3, 5, 4, 3, -1, 7} etc.</p>

<p>This is the solution. You can try to figure it out yourself.</p>

<pre><code>def solve(a, k):
    tbl = {0 : -1}
    sum = 0
    n = len(a)

    for i in xrange(n):
        sum = (sum + a[i]) % k
        if sum in tbl:
               key = tbl[sum]
               result = a[key+1: i+1]
               return result
        tbl[sum] = i
    return []
</code></pre>

python hashtable