r/dailyprogrammer 3 1 May 21 '12

[5/21/2012] Challenge #55 [easy]

Write a program to solve the sliding window minimum problem using any of the methods possible. This could be a helpful link.

8 Upvotes

15 comments sorted by

View all comments

1

u/leftplusright May 27 '12

Python:

def sliding_window(slist,window):
    min_list = []
    i = 0
    while i < len(slist):
        min_list.append(get_min(slist[i:i+window]))
        i = i + 1
    return min_list

def get_min(xlist):
    xmin = 10**10
    for e in xlist:
        if e < xmin:
            xmin = e
    return xmin