NK
BAN USERI might have misunderstood the problem but...my code below seemed to do the trick...
def minWindow(array, keySet):
minSize = len(keySet)
while minSize < len(array):
lowIndex = 0
highIndex = lowIndex + minSize
while (lowIndex + minSize) <= len(array):
if set(array[lowIndex:highIndex]).intersection(keySet) == keySet:
return (lowIndex, highIndex - 1)
lowIndex += 1
highIndex += 1
minSize += 1
return (0, len(array) - 1)
if __name__ == '__main__':
vals = [6,7,1,3,2,4,5,2,3,1,2,5]
keys = set([1, 2, 5])
print minWindow(vals, keys)
This was my shot at it...
class Node(object):
def __init__(self, val, next=None):
self._val = val
self._next = next
def reverseList(head):
newHead = None
while head:
newHead = Node(head._val, newHead)
head = head._next
return newHead
def maxPallindrom(head):
maxPal = []
listItr = head
revListItr = head
while listItr:
revList = reverseList(listItr)
currentPal = checkPal(listItr, revList)
if len(currentPal) > len(maxPal):
maxPal = currentPal
listItr = listItr._next
return maxPal
def checkPal(head1, head2):
currentPal = []
itr1 = head1
itr2 = head2
while (itr1 and itr2) and itr1._val != itr2._val:
itr2 = itr2._next
while (itr1 and itr2) and itr1._val == itr2._val:
currentPal.append(itr1._val)
itr1 = itr1._next
itr2 = itr2._next
return currentPal
if __name__ == '__main__':
head = Node(1, Node(2, Node(3, Node(2, Node(5, Node(7))))))
print maxPallindrom(head)
Not sure if I misunderstood the problem but this worked for me:
- NK January 09, 2016