Graphic Systems Interview Question for Senior Software Development Engineers


Country: United States




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

At the beginning make each sim mark it's position and have them both move in the same direction(Right or Left it doesn't matter), with each coming step make each sim checks whether the current position is marked or not (if not mark it and continue moving in the same direction), since both sims are moving in the same direction the case that a sim steps on a marked position will only happen when one sim steps over the other sim's original position, after that all we have to do is to make the current sim move twice as fast as the other one and they will definitely collide at some point.

Code:

public void collide(){
		if(!isCurrentLocationMarked()){
			markPosition()
			moveLeft();
		}else{
			moveLeft();
			moveLeft();
		}
	}

- sbdul March 22, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

We move left and right, marking position at constant step (stepSize). Checking the presence of no own markers. If found, relax and wait other sim.

public void collide() {
	found = false;
	ownMarkers = 1;
	stepSize = 10;
	step = 0;
	countedMarkers = 1;
	direction = 0;
	this->MarkPosition();
	
	while(!found)
	{
		# Moving step in direction
		if(direction == 0)
		{
			this->MoveLeft();
		}
		else
		{
			this->MoveRight();
		}
		step++;
		
		# Marked Position?
		PositionMarked = this->IsCurrentPositionMarked();
		
		# Own Marker or other sim found?
		if(PositionMarked == True)
		{
			if((step==stepSize) && (countedMarkers < ownMarkers))
			{
				# Found own marker, continue to next own marker (other stepSize moves) in same direction
				countedMarkers++;
				step = 0;
			}
			else
			{
				found = true;
			}
		}
		else
		{
			if(step==stepSize)
			{
				# Other direction
				this->MarkPosition();
				ownMarkers++;
				countedMarkers = 1;
				step = 0;				
				direction = !direction;
			}
		}
		

	}
	
	while(true)
	{
		this->Relax();
	}

- Manuele March 23, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

We move left and right, marking position at constant step (stepSize). Checking the presence of no own markers. If found, relax and wait other sim.

public void collide() {
	found = false;
	ownMarkers = 1;
	stepSize = 10;
	step = 0;
	countedMarkers = 1;
	direction = 0;
	this->MarkPosition();
	
	while(!found)
	{
		# Moving step in direction
		if(direction == 0)
		{
			this->MoveLeft();
		}
		else
		{
			this->MoveRight();
		}
		step++;
		
		# Marked Position?
		PositionMarked = this->IsCurrentPositionMarked();
		
		# Own Marker or other sim found?
		if(PositionMarked == True)
		{
			if((step==stepSize) && (countedMarkers < ownMarkers))
			{
				# Found own marker, continue to next own marker (other stepSize moves) in same direction
				countedMarkers++;
				step = 0;
			}
			else
			{
				found = true;
			}
		}
		else
		{
			if(step==stepSize)
			{
				# Other direction
				this->MarkPosition();
				ownMarkers++;
				countedMarkers = 1;
				step = 0;				
				direction = !direction;
			}
		}
		

	}
	
	while(true)
	{
		this->Relax();
	}

- ghignoliman March 23, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

Given a current sim location, I would radially start exploring the presence of another sim. This means first looking at radius increments of 1,2,3, etc... (i.e look 1unit right / 1 unit left, then 2 units right / 2 units left, etc..) until another sim is found. Once we know the direction in which the other sim is found, we can start moving in that direction by calling moveLeft() or moveRight(). This way, eventually, both sims will collide. I have outlined a simple solution in Python below:

Solution:

def collide():
  # Mark current location
  currSim.markPosition()

  # Radially search for another marked location
  # (this indicates the presence of another sim)
  isRight = True
  increment = 1
  while True:
    rightLocation = currentLocation + increment
    leftLocation = currentLocation - increment
    if isCurrentLocationMarked(rightLocation):
      break
    elif isCurrentLocationMarked(leftLocation):
      isRight = False
      break
    increment += 1

  # If another sim is towards right
  # move right
  if isRight:
    currSim.moveRight()
    currSim.markPosition()
  else: # else move left
    currSim.moveLeft()
    currSim.markPosition()

- prudent_programmer March 22, 2018 | 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