You are viewing a single comment's thread. Return to all comments →
def flatten_queries(queries): my_tups = [] for q in queries: my_tups.append( (q[0], q[2]) ) my_tups.append( (q[1]+1, q[2]*-1) )
sorted_tuples = sorted(my_tups, key=lambda x: (x[0],x[1])) print(f'sorted_tuples: {sorted_tuples}') # {start: [end, acc], ...} f_query = [ [sorted_tuples[0][0], None, sorted_tuples[0][1]] ] max_arr = [sorted_tuples[0][1]] amt = sorted_tuples[0][1] for pt, acc in sorted_tuples[1:-1]: f_query[-1][1] = pt amt += acc tmp = [pt, None, amt] f_query.append(tmp) max_arr.append(f_query[-1][2]) f_query[-1][1] = sorted_tuples[-1][0] print(f'f_query: {f_query}') print(f'max is: {max(max_arr)}') return max(max_arr)
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
def flatten_queries(queries): my_tups = [] for q in queries: my_tups.append( (q[0], q[2]) ) my_tups.append( (q[1]+1, q[2]*-1) )