DEV Community

Ritik Bhola
Ritik Bhola

Posted on

How to reduce complexity in python for the following code?

t = int(input())
for i in range(t)
    n,k = map(int,input().split())
    li = []
    for x in range(n):
        for y in range(n):
            for z in range(n):
                if (x + y + z == n) and (0 < z <= y <= x) and (abs(x - y - z) > k):
                    li.append([x,y,z])

Discussion (0)