StartUp Interview Question for Software Architects


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
0
of 0 vote

We can have a stack here.
Whenever we require an item we can search it fro,m the stack and then put it on the top of the stack which is the most recently used.
Least recently used will be the item which is at the bottom of the stack.

- DashDash March 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

There are 2 ways one implementing Stack and another way using TTL(Time To Live)
-> Using Stack: create a stack Array. let it be size 100. let there be a query which returns the results, then store the result into this Array. Results of diff queries will be stored. suppose if we get the same query, which has result already in Stack, return result from stack and move the Result to the bottom of the stack as it is recent used. So like wise all the reused query results will go to the bottom of stack. Results for the queries which haven't trigged recently , will stay at the top of stack, so can be easily sweeped out of back. But here headache is for each result lot of operations should be done on stack.
-> By using TTL , we will maintain time to each query result. If query again triggers , then we will again start the TTL. So, for every time interval we can flush out the queries whose TTL becomes zero.( means whose result TTL has not restarted.

- Prashanth March 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You have not mentioned a mechanism by which you will search the stack efficiently. When you get a new query, how do you know whether it's already in the stack? If you search the whole stack every time you get a query, it will be O(n) to answer queries.

- eugene.yarovoi March 18, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

As the DataBase operations are costly, it is better i think when compared. It depends on the size of the cache u maintain. if the cache size is more then iteration also takes more time. then one has to reduce their cache size.

- Anonymous March 19, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

linkedlist is one way. the head stores the latest and the tail is the oldest. also keep a hashmap for all nodes in the linkedlist. whenever some new query happens, check whether it's in the hashmap, if yes, move it to the head , if not, remove the tail one and bring the new node to head. besides, update the hashmap every time.

- zyfo2 March 19, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can have a class that contains 2 containers. One is a hash table and the other is a queue. The element in hash table can tell you where it is in queue. When a query is received search for it in hash table. If not found add it to the queue. If found in hash table, we know where it is in Queue. So we can easily remove from (the middle of) the queue and add to it again (at LRU end). This way whole operation is O(n). However it takes slightly more memory.

- Satish June 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about a max heap?each node contains a value representing f(date+time of access). each time node accessed, update value and re-heapify(not the entire heap-simulate the insert node action starting from present index)...O(2*log n) possibly..

- Anonymous October 24, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More