摘要: Given n elements, sort the elements. Here, only one operation is permitted decreaseValue..Note that you cannot swap the values.. output should be a sorted list..if input is 4 5 2 1 3output is 3 3 3.. There can be many answers.. Give the optimum solution with minimum cost. where as cost is the sum of 阅读全文
posted @ 2012-11-09 21:51 chkkch 阅读(437) 评论(0) 推荐(0) 编辑
摘要: 1. There is a stream of numbers, design an effective datastructre to store the numbers and to return the median at any point of time.我们可以考虑维护一个max heap和一个min heap,max heap用来记录数组的前半部分, min heap用来记录数组的后半部分,返回数组的中位数时只要返回大堆的root。当有一个新的数字进来时,可虑是否大于min heap的root,大于的话就放到min heap,它属于数组的后半部分,如果这时min heap的大小大 阅读全文
posted @ 2012-11-09 20:58 chkkch 阅读(949) 评论(1) 推荐(0) 编辑