Understanding combinations in the following code

by Jeevan dsouza   Last Updated August 14, 2019 04:26 AM

I came across this piece of code in a MOOC which apparently be solved using permutation and combinations

I tried running this code but the code has O(n3) complexity and would take a long time to compile

n = 1000
count = 0

for i in range(n):
    for j in range(n):
        for k in range(n):
            if i < j and j < k:
                count += 1

print(count)

What will the answer be and how to solve it using combinations?



Related Questions


Updated June 26, 2017 17:26 PM

Updated June 04, 2017 01:26 AM

Updated February 08, 2019 22:26 PM

Updated June 06, 2019 00:26 AM

Updated August 18, 2018 15:26 PM