Coding
Published on

Codesignal - shapeArea solution

Authors

The solutions here are quite similar in a sense that all are based on math.

Solution one:

def shapeArea(n):
    return n*n + (n-1)*(n-1)

Solution two:

def shapeArea(n):
    return n**2 + (n-1)**2

Solution three:

def shapeArea(n):
    return 2*n*(n-1) + 1

Solution four:

def shapeArea(n):
    result = 1

    for i in range(n):
        result += 4 * i

    return result