Thanks for your test case. I am improving my solution now.
Time Limit Exceeded
Can anyone help me optimize it????
class game:def __init__(self, N, max_questions, array, questions):self.gameOn(max_questions, array, questions)def gameOn(self, max_questions, array, questions):runs = 1array.sort()stack = arraytop = len(stack) - 1queue = front, rear = 0, 0#while runs <= max_questions:# 1) Stack empty 2) Queue Emptywhile top >= 0 or (front < rear and rear!=0):#if runs > max_questions: break#print stack[0:top+1], queue[front:rear+1], top, front, rear#For stack emptyif top < 0:element = queue[front]
Here is my Python Solution for the program. I used the concept of MergeSort to solve the problem (O log N). I am getting 2 test cases correct in each section and rest are Run Time error. (This happens with me very often on CodeChef + Python, probably because of raw_input().split() thing). But if anyone can give me test case where this program genuiley fails then I will be happy to learn the same :)
class triathlon:def __init__(self, N, database):self.mergeSort(database, 0, len(database)-1)#print databaseprint self.cal_time(database)def mergeSort(self, array, left, right):if left < right:mid = (left + right)/2self.mergeSort(array, left, mid)self.mergeSort(array, mid + 1, right)self.merge(array, left, mid, right)def merge(self, array, left, mid, right):
This happens with me all the time. I am failing to create a case where the program is failing to produce the correct output. Whereas on CodeChef except for 2 all the cases are failing. Can you please give me cases where my program is failing so that I can improve it.
class matchedBrackets:def __init__(self, N, array):self.gameOn(array)def gameOn(self, array):StartNesting = 0MaxNesting = 0StartSequence = 0MaxSequence = 0tempNestingStart = 0tempNestingDepth = 0tempSeqStart = 0tempSeqLength = 0stack = for index, element in enumerate(array):