前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[mitbbs面经][Google] k largest elements

[mitbbs面经][Google] k largest elements

作者头像
包子面试培训
发布2018-04-20 16:19:59
9970
发布2018-04-20 16:19:59
举报
文章被收录于专栏:包子铺里聊IT

mitbbs google 最新算法题讲解,sliding window 中查找top K元素。

发题人id:zerocoolcode

发题时间: 3/25/2015

出题公司:google

原帖链接:http://www.mitbbs.com/article_t/JobHunting/32918239.html

题目引用

Find k-largestelements in a sliding window

A long array A[]with size n is given to you. There is a sliding window of size w which is moving from the very left of thearray to the very right. You can only see the wnumbers in the window. Each time the sliding window moves rightwards by oneposition. Find top k elements in thesliding window when it moves to each n positions.

包子解答

正如发帖人所述,这道题目是Sliding Window Maximum的变种。如果只是要求最大的元素,那么可以通过原题讲解中的堆栈解法以O(n) 的复杂度解决。当要求输出所有sliding window 的top k 大的元素时,通过直觉,我们可以知道总共有 k*n次输出,所以最少 O(k*n)的时间复杂度是逃不掉的。在这里,包子以多种思路来讲解此题,希望大家能有所收获。

(点击左下角原文链接查看全文)

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2015-04-02,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 包子铺里聊IT 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档