
Data Structure Design
文章平均质量分 71
flyatcmu
这个作者很懒,什么都没留下…
展开
-
Design Bitset
ABitsetis a data structure that compactly stores bits.Implement theBitsetclass:Bitset(int size)Initializes the Bitset withsizebits, all of which are0. void fix(int idx)Updates the value of the bit at the indexidxto1. If the value was alrea...原创 2022-02-06 12:45:31 · 159 阅读 · 0 评论 -
All O`one Data Structure
Implement a data structure supporting the following operations:Inc(Key) - Inserts a new keywith value 1. Or increments an existing key by 1. Key is guaranteed to be anon-emptystring. Dec(Key) - If Key's value is 1, remove it from the data structure. ...原创 2020-06-30 13:26:01 · 202 阅读 · 0 评论 -
LFU Cache
LFU (Least Frequently Used) is a famous cache eviction algorithm.For a cache with capacityk, if the cache is full and need to evict a key in it, the key with the lease frequently used will be kicke...原创 2020-01-03 11:50:17 · 485 阅读 · 0 评论 -
Design Browser History
You have abrowserof one tab where you start on thehomepageand you can visit anotherurl, get back in the history number ofstepsor move forward in the history number ofsteps.Implement theBrowserHistoryclass:BrowserHistory(string homepage)Initi...原创 2020-06-07 12:36:01 · 344 阅读 · 0 评论 -
First Unique Number in Data Stream
Given a continuous stream of data, write a function that returns the first unique number (including the last number) when the terminating number arrives. If the unique number is not found, return-1....原创 2020-01-02 14:02:14 · 658 阅读 · 1 评论 -
First Unique Number in Data Stream II
We need to implement a data structure namedDataStream. There aretwomethods required to be implemented:void add(number)// add a new number int firstUnique()// return first unique numberExample...原创 2019-11-15 13:56:37 · 1023 阅读 · 0 评论 -
Add and Search Word - Data structure design
Design a data structure that supports the following two operations:void addWord(word)bool search(word)search(word) can search a literal word or a regular expression string containing only le...原创 2016-09-11 11:40:17 · 488 阅读 · 0 评论 -
Insert Delete GetRandom O(1)
Design a data structure that supports all following operations in averageO(1) time.insert(val): Inserts an item val to the set if not already present. remove(val): Removes an item val from the s...原创 2016-08-24 14:40:30 · 456 阅读 · 0 评论 -
Insert Delete GetRandom O(1) - Duplicates allowed
Design a data structure that supports all following operations inaverageO(1)time.Note: Duplicate elements are allowed.insert(val): Inserts an item val to the collection. remove(val): Removes a...原创 2016-10-20 11:00:18 · 260 阅读 · 0 评论 -
Add, Search, Delete Node in BST.
Add Node, Search Node, Delete Node, 的基本操作,被问了两次了。写出来。http://quiz.geeksforgeeks.org/binary-search-tree-set-1-search-and-insertion/ // add the node; public TreeNode addNode(TreeNode root, int v...原创 2016-10-14 07:37:33 · 302 阅读 · 0 评论 -
Design Circular Queue
用circular array去implement queue,这个题目被面到两次了。昨天onsite被问到了。今天看了下正确答案,确实不难,是自己复习不到位。算法就是:用front 和rear分别表示头和尾,最重要的考点就是用count来表示里面有多少个元素。这样 front和rear只需要一直向前走就可以了。每次enqueue和dequeue的时候,都用size,也就是count来...原创 2016-10-14 05:39:58 · 1560 阅读 · 0 评论 -
LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the value (will always be positive) of the key if th...原创 2014-12-15 14:50:00 · 514 阅读 · 0 评论 -
Peeking Iterator
Given an Iterator class interface with methods:next()andhasNext(), design and implement a PeekingIterator that support thepeek()operation -- it essentially peek() at the element that will be r原创 2016-09-08 07:48:55 · 349 阅读 · 0 评论 -
Zigzag Iterator
Given two 1d vectors, implement an iterator to return their elements alternately.For example, given two 1d vectors:v1 = [1, 2]v2 = [3, 4, 5, 6]By callingnextrepeatedly untilhasNext原创 2016-09-08 13:03:32 · 302 阅读 · 0 评论 -
Implement Set using Array.
参考链接:http://faculty.washington.edu/moishe/javademos/ch03%20Code/jss2/ArraySet.java被Pivotal的面试官给问到了,trick的地方在于remove的那一块,要把最后的元素跟自己remove的元素进行互换,然后count--;//****************************************转载 2016-09-10 02:08:51 · 706 阅读 · 0 评论