Yahoo Interview Question for Software Engineer / Developers






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

public interface vehicles{
public boolean park(ParkingSlot slot);
}

public class Motorbike implement vehicles{
public boolean park(ParkingSlot slot){
if(slot is motobikeslot) return true;
return false;
}
}

public class Cars implement vehicles{
public boolean park(ParkingSlot slot){
if(slot is Carslot) return true;
return false;
}
}

public class handicappedCars implement vehicles{
public boolean park(ParkingSlot slot){
if(slot is Carslot or handicappedslot) return true;
return false;
}
}

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

We have to maintain two states. One indicating the available parking lots(category wise) and parked lots.
HashMap of Vehicle.Type and Stack of positions for holding available parking lots.
HashMap of Position and Vehicle.

- Hinax September 20, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{
import java.util.List;

public abstract class Vehicle
{
List<ParkingLot> pLst = null;

ParkingLot plot = null;

public void setpLst(List<ParkingLot> pLst)
{
this.pLst = pLst;
}

public abstract void parkVehicle();

public ParkingLot getParkingLot(List<ParkingLot> plist, ParkingLotType plt)
{

for (ParkingLot pL : plist)
{

if (pL.getpLType() == plt)
{
if (pL.isOccupied() == false)
{
pL.setOccupied(true);
plist.remove(pL);
return pL;
}

}

}

return null;
}

public void unParkVehicle(ParkingLot pL)
{

pL.setOccupied(true);
pLst.add(pL);
}

}

class MotorBike extends Vehicle
{

@Override
public void parkVehicle()
{

ParkingLotType plTArray = ParkingLotType.MOTORBIKE;

plot = super.getParkingLot(pLst, plTArray);

}

}

class Car extends Vehicle
{

@Override
public void parkVehicle()
{
// TODO Auto-generated method stub

// plTArray = new ParkingLotType[1];
ParkingLotType plTArray = ParkingLotType.CAR;

plot = super.getParkingLot(pLst, plTArray);

}

}

class HandiCar extends Vehicle
{

@Override
public void parkVehicle()
{

ParkingLotType plTArray = ParkingLotType.HANDICAPPED_LOT;

plot = super.getParkingLot(pLst, plTArray);

if (plot == null)
plot = super.getParkingLot(pLst, ParkingLotType.CAR);

}

}

class ParkingLot
{
private int id;
private boolean occupied = false;
private ParkingLotType pLType;

public int getId()
{
return id;
}

public ParkingLot(int id, boolean occupied, ParkingLotType pLType)
{
super();
this.id = id;
this.occupied = occupied;
this.pLType = pLType;
}

public ParkingLotType getpLType()
{
return pLType;
}

public boolean isOccupied()
{
return occupied;
}

public void setOccupied(boolean occupied)
{
this.occupied = occupied;
}

@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + id;
return result;
}

@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ParkingLot other = (ParkingLot) obj;
if (id != other.id)
return false;
return true;
}

}

enum ParkingLotType
{
MOTORBIKE, CAR, HANDICAPPED_LOT;
}

}

- super Man November 09, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

;DROP TABLE --

- Anonymous December 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

;DROP TABLE --

- Anonymous December 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sorry..was learning SQL injection..typed in the wrong site.

- Anonymous December 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sorry..was learning SQL injection..typed in the wrong site.

- Anonymous December 06, 2011 | 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