## Adobe Interview Question for MTSs

• 0
of 0 votes

Country: United States
Interview Type: In-Person

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

``````/*
Mix all Ei and Si
Sort this Mix (ascending)
now scan this sorted E/S list
Let visitors=0
for every E encountered: visitors +=1
for every S encountered: visitors -=1
If there is a pair (consecutive <E,S> with the same time stamp, you can drop this   tuple ).The visitor count is going to remain the same

Now you have a timeline tagged with #visitors on site and
for any time T in the query, you can read out the visitor value

*/``````

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

``````public static void main(String args[]) {
IT it = null;

it = add(it, new IT(15, 20));
it = add(it, new IT(10, 30));
it = add(it, new IT(17, 19));
it = add(it, new IT(5, 20));
it = add(it, new IT(12, 15));
it = add(it, new IT(30, 40));

System.out.println(getCount(it, 18, 0));
}

public static int getCount(IT it, int t, int count){
if(it == null)
return count;
if(t < it.st || t <= it.max)
count = getCount(it.left, t, count);
if(t > it.st || t >= it.max)
count = getCount(it.right, t, count);
if(t >= it.st && t <= it.en)
count += 1;
return count;
}

public static IT add(IT it, IT node){
if(it == null){
it = node;
it.max = node.en;
}
else
addIn(it, node);
update(it);
return it;

}

public static void addIn(IT it, IT node){
if(it.st > node.st && it.left == null){
it.left = node;
node.max = node.en;
}
if(it.st < node.st && it.right == null){
it.right = node;
node.max = node.en;
}
int lm = -1;
int rm = -1;
if(it.st > node.st)
addIn(it.left, node);
if(it.st < node.st)
addIn(it.right, node);
node.max = Math.max(lm, rm);
node.max = Math.max(node.max, node.en);
}

public static int update(IT it){
if(it.left == null && it.right == null)
return it.max;
if(it.left == null)
return it.right.max;
if(it.right == null)
return it.left.max;

int lm = update(it.left);
int rm = update(it.right);
it.max = Math.max(lm, rm);
it.max = Math.max(it.max, it.en);
return it.max;
}

static class IT{
int st;
int en;
int max;

IT left;
IT right;

public IT(int st, int en){
this.st = st;
this.en = en;
}
}``````

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

This question can be converted into following question:

For given time during [TS, TE], how many user user active time(Si, Ei) has overlap with the given time during. In another word, count the number of (Si, Ei) that overlapping with [TS, TE].

If (Si, Ei) NOT overlapping with [TS, TE], there are TWO scenarios:
1. (Si, Ei) is ahead of [TS,TE] as a whole. Denote: Ei > TS
2. (Si, Ei) is behind of[TS, TE] as a whole. Denote: TE > Si

If none of above two scenarios exist, we know these two duration overlapping.

Python solution:

``````# input is list[][]
def activeUsers(self, input, TS, TE):
count = 0
for i in range(input):
if not (input[i] < TE or input[i] > TS):
count += 1
return count``````

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

Sort all tuples based on end time. Then iterate the sorted list and use stack to push new user when seeing start time and pop user when seeing end time. Keep track of max user count in the stack which is the answer.

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

``````int usersActive(int s[], int e[], int n)
{
sort(s, s+n);
sort(e, e+n);

int users = 1, result = 1;
int i = 1, j = 0;

while (i < n && j < n)
{
if (s[i] < e[j])
{
users++;
i++;

if (users > result)
result = users;
}
else
{
users--;
j++;
}
}

return result;
}``````

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

``````int usersActive(int s[], int e[], int n)
{
sort(s, s+n);
sort(e, e+n);

int users = 1, result = 1;
int i = 1, j = 0;

while (i < n && j < n)
{
if (s[i] < e[j])
{
users++;
i++;

if (users > result)
result = users;
}
else
{
users--;
j++;
}
}

return result;``````

}

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