Reconstruct the array by replacing arr[i] with (arr[i-1]+1) % M

def construct(n, m, a):

ind = 0

for i in range(n):

if (a[i]!=-1):

ind = i

break

for i in range(ind-1, -1, -1):

if (a[i]==-1):

a[i]=(a[i + 1]-1 + m)% m

for i in range(ind + 1, n):

if(a[i]==-1):

a[i]=(a[i-1]+1)% m

print(*a)

n, m = 6, 7

a =[5, -1, -1, 1, 2, 3]

construct(n, m, a)

Program for Number of stopping station problem

def stopping_station( p, n):

num = 1

dem = 1

s = p

while p != 1:

dem *= p

p-=1

t = n - s + 1

while t != (n-2 * s + 1):

num *= t

t-=1

if (n - s + 1) >= s:

return int(num/dem)

else:

return -1

num = stopping_station(4, 12)

if num != -1:

print(num)

else:

print("Not Possible")


Pattern matching with Regex

import re

phoneNumRegex = re.compile(r'\d\d\d-\d\d\d-\d\d\d\d')

mo = phoneNumRegex.search('My number is 415-555-4242.')

print('Phone number found: ' + mo.group())



Draw Among Us Character with Turtle

import turtle

color1 =  'yellow'

color2 = ''

color3 = 'skyblue'

color4 = ''

s = turtle.getscreen()

t = turtle.Turtle()

def x():

    t.pensize(20)

    t.fillcolor(color1)

    t.begin_fill()

    t.right(90)

    t.forward(50)

    t.right(180)

    t.circle(40, -180)

    t.right(180)

    t.forward(200)

    t.right(180)

    t.circle(100, -180)

    t.backward(20)

    t.left(15)

    t.circle(500, -20)

    t.backward(20)

    t.circle(40, -180)

    t.left(7)

    t.backward(50)

    t.up()

    t.left(90)

    t.forward(10)

    t.right(90)

    t.down()

    t.right(240)

    t.circle(50, -70)

    t.end_fill()

def glass():

    t.up()

    t.right(230)

    t.forward(100)

    t.left(90)

    t.forward(20)

    t.right(90)

    t.down()

    t.fillcolor(color3)

    t.begin_fill()

    t.right(150)

    t.circle(90, -55)

    t.right(180)

    t.forward(1)

    t.right(180)

    t.circle(10, -65)

    t.right(180)

    t.forward(110)

    t.right(180)

    t.circle(50, -190)

    t.right(170)

    t.forward(80)

    t.right(180)

    t.circle(45, -30)

    t.end_fill()

def y():

    t.up()

    t.right(60)

    t.forward(100)

    t.right(90)

    t.forward(75)

    t.fillcolor(color1)

    t.begin_fill()

    t.down()

    t.forward(30)

    t.right(255)

    t.circle(300, -30)

    t.right(260)

    t.forward(30)

    t.end_fill()

x()

glass()

y()

turtle.done()

Colored Hexagons Turtle

import turtle

from random import randint

x = 20

y = 20

turtle.speed(300)

turtle.colormode(255)

def move(l, a):

                turtle.right(a)

                turtle.forward(l)

def hex():

        turtle.pendown()

        turtle.color( randint(0,255),randint(0,255),randint(0,255) )

        turtle.begin_fill()

        for i in range(6):

                move(x,-60)

        turtle.end_fill()

        turtle.penup()

turtle.penup()

for color in range (y):

        if color == 0:

                hex()

                move(x,-60)

                move(x,-60)

                move(x,-60)

                move(0,180)

        for i in range (6):

                move(0,60)

                for j in range (color+1):

                        hex()

                        move(x,-60)

                        move(x,60)

                move(-x,0)

        move(-x,60)

        move(x,-120)

        move(0,60)

turtle.exitonclick()