Ebay Interview Question for Software Engineer / Developers






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

for (i = 0; i < arr.size(); i++) {
arr.remove(i);
}

- ananthakrishnan.s.r July 12, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This one will work. the size() function will reduce each time the number is deleted. And as you are deleting it from front, whenever a number is deleted, the array is re-organized. So, eventually, you will be skipping one number each time you increment i once.

- Jay August 02, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

why would you want to compute size() everytime?

- cwackked August 18, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes, valid point. It can be done like this,

n=arr.size();
n=n/2+n%2;
for (int i = 0; i < n; i++) {
arr.remove(i);
}
Is it perfect now?

- ananthakrishnan.s.r August 18, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

or from tail to head, no need for size() each time:

int i = arr.size() - 1;
while (i >= 0){
  arr.remove(i);
  i -= 2;
}

- rokanet August 25, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public void removeAlternate(){
int j =operation.size();
for(in i=1;i<j/2;i++;){
remove(operation.size()-i+isOdd(j))
}
}

public int isOdd(int){
if(isodd) return 1;
else return 0;
}

- Anonymous August 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int counter=0

while(list.size() > counter)
{
list.remove(list.size() - counter - 1);
counter++;
}

- Anonymous August 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

ArratList a;
int n=a.size();
for(int i=1;i <= n/2;++i)
a.remove(i);

- sachin October 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

for(i=1;i<a.size();i=i+2)
{
a.remove(a.size()-i);
}

- Rochak June 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

this is an arraylist and it will keep updating once u delete the front element...so u need to start deleting from the end.

- USCGrad April 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Iterator<Integer> it = al.iterator();
while (it.hasNext()) {
System.out.println(it.next());
if (it.hasNext()) {
System.out.println("del:" + it.next());
it.remove();
}
}

- Anonymous October 31, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Iterator<Integer> it = al.iterator();
		while (it.hasNext()) {
			System.out.println(it.next());
			if (it.hasNext()) {
				System.out.println("del:" + it.next());
				it.remove();
			}
		}

- Anonymous October 31, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

ArratList a;
for(int i=0;i<a.size();i+=2)
a.remove(i);

- gullu October 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this one is wrong

- Anonymous August 25, 2011 | Flag
Comment hidden because of low score. Click to expand.
-2
of 2 vote

ArratList a;
int n=a.size();
for(int i=1;i <= n/2;++1)
a.remove(i);

- sachin October 21, 2010 | 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