Hired.com Interview Question for Java Developers


Country: United States
Interview Type: Phone Interview




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

Follow up. What if you wanted to improve on the storage space? e.g. I got a million items for a window and I wouldn't want to store all of them in memory.

- dmachop June 11, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Some examples would be nice. What does it mean "it can keep M items in N milliseconds"? Does it mean that item must be evicted from it after N milliseconds and that there must be at most M items?

- emb June 11, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@emb Yes. This is what is given to me and you can add any member/methods on top of this class. When this deals with a size limited buffer, there should be an eviction logic along with this. For example, limitBuffer(1000, 20) means that the instance can hold a maximum of 20 items in 1 millisecond. If there are about 20 items and a new item is about to be added within a span of 1 millisecond, the class should call alert stating that this item could not be added because maximum capacity has exceeded. A few practical examples that I can think about is the maximum messages that can be held by a mailbox for a year or the maximum api calls that is held per day.

- dmachop June 11, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class LimitBuffer
{
long m_wms;
int m_threshold;
long m_startt;
long m_lastt;
int m_count;
class Event
{
String name;
long time;
Event(String name,long time) {
this.name = name;
this.time = time;
}
}
LinkedList<Event> eventlist;
public LimitBuffer(long windowMs, int threshold)
{
eventlist = new LinkedList<Event>();
m_startt = System.currentTimeMillis( );
m_count = 0;
m_wms = windowMs;
m_threshold = threshold;
}
private void alert(String eventName)
{
System.out.println(eventName);
}
public void addEvent(String eventName)
{
m_lastt=System.currentTimeMillis( );
Event a = new Event(eventName,m_lastt);
eventlist.add(a);
m_count++;
if(m_count >= m_threshold)
{
Event x = eventlist.removeFirst();
m_count—;
if(x.time - m_lastt< m_wms)
alert(x.name); }
}
}

- jingnanzhubj July 12, 2016 | 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