Epic Systems Interview Question for Developer Program Engineers


Country: United States




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

public class Solution {
	private static int steps = 0;//Total steps taken so far
	private static int distanceFromStart = 0;//Current distance from start
	private static int multiplier = 1;//For 1x, 2x, 3x etc.
	private static boolean moveDirection = true;//right direction means true, left means false
	private static int nextMove = 0;
	private static int x = 0;
	private static int y = 0;
	private static int totSteps = 0;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		distance(1,5,8);
		System.out.println(distanceFromStart);
	}
	
	public static void distance(int x, int y, int totSteps){
		Solution.x = x;
		Solution.y = y;
		Solution.totSteps = totSteps;
		
		while(steps<totSteps){
			nextMove = multiplier*x;//odd moves  1x, 2x, 3x
			considerTotalSteps();			
			considerYAndDirectionChange();
			if(moveDirection==true){
				moveDirection=false;
			}else{
				moveDirection=true;
			}
			nextMove = multiplier + x;//even moves 1+x, 2+x, 3+x
			considerTotalSteps();			
			considerYAndDirectionChange();
			if(moveDirection==true){
				moveDirection=false;
			}else{
				moveDirection=true;
			}
			multiplier++;
		}
	}
	
	private static void considerTotalSteps(){
		if((steps+nextMove) > totSteps){
			nextMove = totSteps - steps;//Only as many steps to sum up to totSteps
			steps = totSteps;
		}else{
			steps = steps + nextMove;
		}
		System.out.println("next move "+ nextMove);
	}
	
	private static void considerYAndDirectionChange(){
		int changeDirection = nextMove/y;//without offset
		int offset = 0;
		if(moveDirection == true){
			offset = distanceFromStart;
		}else{
			offset = y - distanceFromStart;
		}
		if((offset+(nextMove%y))>=y){
			changeDirection++;
		}
		if(changeDirection%2==1){
			if(moveDirection==true){
				moveDirection=false;
			}else{
				moveDirection=true;
			}
		}
		int newOffset = (offset+(nextMove%y))%y;
		if(moveDirection==true){
			distanceFromStart = newOffset;
		}else{
			distanceFromStart = y - newOffset;
		}
		System.out.println("current distance "+distanceFromStart);
	}

}

- s100banerjee May 01, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

your answer gives 2 but it should eb 4 right?

- ron August 09, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<math.h>

int y=0;
int a=1;
int distance=0;
int direction=1;
int total_steps=0;
int current_total=0;

void move(int x){
int remaining_part;
if(x<0){
for(int i=-1; i>=x;i--){
if((current_total+1)<=total_steps){
if((current_total%y !=0)||(current_total==0)){
current_total=current_total+1;
distance=distance+ (-direction)*1;
}
else{
direction=(-1)*direction;
remaining_part=abs(x-i)+1;
if(current_total+remaining_part>total_steps){
remaining_part=total_steps-current_total;

}

distance=distance+(-direction)*remaining_part;
current_total=current_total+remaining_part;
return;

}
}
else{
return;
}
}
}
else{
for(int i=1; i<=x;i++){
if((current_total+1)<=total_steps){
if((current_total%y !=0)||(current_total==0)){
current_total=current_total+1;
distance=distance+ direction*1;
}
else{
direction=(-1)*direction;
remaining_part=abs(x-i)+1;
if(current_total+remaining_part>total_steps){
remaining_part=total_steps-current_total;

}

distance=distance+direction*remaining_part;
current_total=current_total+remaining_part;
return;

}
}
else{
return;
}
}


}

}

int main(){
int x;
printf("Enter the values for X , Y and Total \n");
scanf("%d %d %d",&x,&y,&total_steps);
while(current_total<total_steps){
move(direction*a*x);
move((-direction)*(x+a));
a=a+1;

}
printf("The distance travelled is %d ",abs(distance));
}

- Ashwani June 07, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<math.h>

int y=0;
int a=1;
int distance=0;
int direction=1;
int total_steps=0;
int current_total=0;

void move(int x){
int remaining_part;
if(x<0){
for(int i=-1; i>=x;i--){
if((current_total+1)<=total_steps){
if((current_total%y !=0)||(current_total==0)){
current_total=current_total+1;
distance=distance+ (-direction)*1;
}
else{
direction=(-1)*direction;
remaining_part=abs(x-i)+1;
if(current_total+remaining_part>total_steps){
remaining_part=total_steps-current_total;

}

distance=distance+(-direction)*remaining_part;
current_total=current_total+remaining_part;
return;

}
}
else{
return;
}
}
}
else{
for(int i=1; i<=x;i++){
if((current_total+1)<=total_steps){
if((current_total%y !=0)||(current_total==0)){
current_total=current_total+1;
distance=distance+ direction*1;
}
else{
direction=(-1)*direction;
remaining_part=abs(x-i)+1;
if(current_total+remaining_part>total_steps){
remaining_part=total_steps-current_total;

}

distance=distance+direction*remaining_part;
current_total=current_total+remaining_part;
return;

}
}
else{
return;
}
}


}

}

int main(){
int x;
printf("Enter the values for X , Y and Total \n");
scanf("%d %d %d",&x,&y,&total_steps);
while(current_total<total_steps){
move(direction*a*x);
move((-direction)*(x+a));
a=a+1;

}
printf("The distance travelled is %d ",abs(distance));
}

- Ashwani June 07, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<math.h>

int y=0;
int a=1;
int distance=0;
int direction=1;
int total_steps=0;
int current_total=0;

void move(int x){
int remaining_part;
if(x<0){
for(int i=-1; i>=x;i--){
if((current_total+1)<=total_steps){
if((current_total%y !=0)||(current_total==0)){
current_total=current_total+1;
distance=distance+ (-direction)*1;
}
else{
direction=(-1)*direction;
remaining_part=abs(x-i)+1;
if(current_total+remaining_part>total_steps){
remaining_part=total_steps-current_total;

}

distance=distance+(-direction)*remaining_part;
current_total=current_total+remaining_part;
return;

}
}
else{
return;
}
}
}
else{
for(int i=1; i<=x;i++){
if((current_total+1)<=total_steps){
if((current_total%y !=0)||(current_total==0)){
current_total=current_total+1;
distance=distance+ direction*1;
}
else{
direction=(-1)*direction;
remaining_part=abs(x-i)+1;
if(current_total+remaining_part>total_steps){
remaining_part=total_steps-current_total;

}

distance=distance+direction*remaining_part;
current_total=current_total+remaining_part;
return;

}
}
else{
return;
}
}


}

}

int main(){
int x;
printf("Enter the values for X , Y and Total \n");
scanf("%d %d %d",&x,&y,&total_steps);
while(current_total<total_steps){
move(direction*a*x);
move((-direction)*(x+a));
a=a+1;

}
printf("The distance travelled is %d ",abs(distance));
}

- jha June 07, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<math.h>

int y=0;
int a=1;
int add=11;
int subtract=22;
int distance=0;
int direction=1;
int total_steps=0;
int current_total=0;

void move(int x,int movement){
	int remaining_part;
	int abs_x=abs(x);
	for(int i=1; i<=abs_x;i++){
		if((current_total+1)<=total_steps){
			if((current_total%y !=0)||(current_total==0)){
				current_total=current_total+1;
				if(movement==subtract)
					distance=distance+ (-direction)*1;
				else if(movement==add)
					distance=distance+ direction*1;
				
			}
			else{
				direction=(-1)*direction;
				remaining_part=abs_x-i+1;
				if(current_total+remaining_part>total_steps){
					remaining_part=total_steps-current_total;
				}
				if(movement==subtract)
					distance=distance+ (-direction)*remaining_part;
				else if (movement==add)
					distance=distance+ (direction)*remaining_part;
				current_total=current_total+remaining_part;
				return;
			
			}	
		}
		else{
			return;
		}
	}
}

int main(){
	int x;
	printf("Enter the values for X , Y and Total \n");
	scanf("%d %d %d",&x,&y,&total_steps);
	while(current_total<total_steps){
		move(a*x,add);
		move((x+a),subtract);
		a=a+1;

	}
	printf("The distance travelled is  %d ",abs(distance));
}

- jha jha June 07, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Glitch_robot_distance {


    public static void main(String args[])
    {
        move(2,2,5);
    }
    static void move(int x, int y, int steps)
    {
        int distance=0;
        boolean forward=true;
        for( int i=1;i<=steps;i++)
        {

            if(forward)
                distance+= (x + i) - (x * i);
            
            else
                distance-=(x+i)-(x*i);
            
            if((i%y)==0)
            forward=!forward;

        }

        System.out.println(distance);

    }
}

- Aziz August 18, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Glitch_robot_distance {


    public static void main(String args[])
    {
        move(2,2,5);
    }
    static void move(int x, int y, int steps)
    {
        int distance=0;
        boolean forward=true;
        for( int i=1;i<=steps;i++)
        {

            if(forward)
                distance+= (x + i) - (x * i);
            
            else
                distance-=(x+i)-(x*i);
            
            if((i%y)==0)
            forward=!forward;

        }

        System.out.println(distance);

    }
}

- Aziz August 18, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Glitch_robot_distance {


    public static void main(String args[])
    {
        move(2,2,5);
    }
    static void move(int x, int y, int steps)
    {
        int distance=0;
        boolean forward=true;
        for( int i=1;i<=steps;i++)
        {

            if(forward)
                distance+= (x + i) - (x * i);
            
            else
                distance-=(x+i)-(x*i);
            
            if((i%y)==0)
            forward=!forward;

        }

        System.out.println(distance);

    }

}

- Aziz August 18, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Glitch_robot_distance {


public static void main(String args[])
{
move(2,2,5);
}
static void move(int x, int y, int steps)
{
int distance=0;
boolean forward=true;
for( int i=1;i<=steps;i++)
{

if(forward)
distance+= (x + i) - (x * i);

else
distance-=(x+i)-(x*i);

if((i%y)==0)
forward=!forward;

}

System.out.println(distance);

}
}

- Aziz August 18, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Glitch_robot_distance {


    public static void main(String args[])
    {
        move(2,2,5);
    }
    static void move(int x, int y, int steps)
    {
        int distance=0;
        boolean forward=true;
        for( int i=1;i<=steps;i++)
        {

            if(forward)
                distance+= (x + i) - (x * i);
            
            else
                distance-=(x+i)-(x*i);
            
            if((i%y)==0)
            forward=!forward;

        }

        System.out.println(distance);

    }
}

- Aziz August 18, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Scanner;
public class Glitch {
	public static void main(String[] args){
		//program specification asks thats you prompt for input
		Scanner keyboard = new Scanner(System.in);
		System.out.print("x = ");
		int x = keyboard.nextInt();
		System.out.print("y = ");
		int y = keyboard.nextInt();
		System.out.print("total steps = ");
		int totalSteps = keyboard.nextInt();
		
		//run the Glitch Robot
		GlitchRobot glitch = new GlitchRobot(x,y,totalSteps);
		glitch.run();
		System.out.println(glitch);
	}
	private static class GlitchRobot{
		int totalSteps;
		int startLocation;
		int curLocation;
		int x;
		int y;
		int direction;//either 1 or -1
		public GlitchRobot(int x, int y,int totalSteps){
			
			this.totalSteps = totalSteps;
			startLocation = 0; 
			curLocation = 0;
			this.x = x;
			this.y = y;
			direction = 1;//starts in positive direction (out multiplier)
		}
		public void run(){
			int stepCounter = 0;
			int stepIterator = 0;
			while(stepCounter<totalSteps){
				
				curLocation += (x * (stepIterator+1)) * direction;
				stepCounter += (x * (stepIterator+1));
				if(stepCounter>=totalSteps){
					//we could be past totals steps so break
					break;
				}
				//if y divides stepCounter turn 180 degrees. Since there are two different types of steps we have to compute it twice
				if( y % stepCounter == 0)
					direction*=-1;
		
				curLocation -= (x + (stepIterator+1)) * direction;
				stepCounter += (x + (stepIterator+1));
				
				if(y % stepCounter == 0)
					direction*=-1;
				
				stepIterator++;
			}
		}
		@Override
		public String toString(){
			return "steps from starting point: "+Math.abs(curLocation-startLocation);
		}
	}
		
	
}

- epicfail November 04, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Example solution in MATLAB that counts each step:

C = input('Enter three integers: x, y, and total number of steps, as a three element array.\nExample: [3 10 56]\n');
x=C(:,1);
y=C(:,2);
totalsteps=C(:,3);

direction = 1; %changes when robot flips 180 (i.e. total steps is a multiple of y)
currsteps = 0; %counter for total steps
distance = 0; %counter for distance from origin
level = 0; %level of steps, (ie 2x (level 2), 3x (level 3), 4x)

while currsteps<totalsteps
level = level+1
c = 0; %resettable counter for steps
cdum = x*level; %dummy variable for absolute value of current 1x, 2x, etc step
while c<cdum
c=c+1;
currsteps = currsteps+1;
distance = distance+1*direction;
if rem(currsteps,y)==0
direction = direction.*-1
end
if currsteps==totalsteps break
end
end
c=0;
cdum = x+level; %absolute value of current 1+x, 2+x, etc step
if currsteps==totalsteps break
end
while c<cdum
c=c+1;
currsteps = currsteps+1;
distance = distance-1*direction;
if rem(currsteps,y)==0
direction = direction.*-1
end
if currsteps==totalsteps break
end
end
end

fprintf('Glitch the robot ends up %f steps away from his starting point.', distance

- coderman November 22, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Main {
    public static int x = 3;
    public static int y = 400;
    public static int totalSteps = 500;

    public static void main(String[] args) {
        Robot robot = new Robot();
        int position = robot.go(x, y, totalSteps);
        System.out.println(new StringBuilder("x = ").append(x).append("; y = ").append(y).append("; totalSteps = ")
                .append(totalSteps).append("; Result: ").append(position).toString());
    }
}

class Robot {
    public Robot() {}

    public int go(int x, int y, int totalSteps) {
        if ( x < 0 || y < 0 ) {
            throw new IllegalArgumentException("Robot cannot move negative number of steps, but at least one of input parameters is negative.");
        }
        if (totalSteps <= 0) {
            return 0;
        }
        int currentPosition = 0;
        int currentDirection = 1;
        int totalStepsPassed = 0;
        Movement[] movements = {new MovementEven(x), new MovementOdd(x)};
        int i = 1;

        while (totalStepsPassed < totalSteps) {
            Movement movement = movements[i++ % movements.length];
            movement.ready();
            while(movement.isNextStep() && totalStepsPassed < totalSteps) {
                currentPosition += movement.step() * currentDirection;
                totalStepsPassed++;
                if (totalStepsPassed == y) {
                    currentDirection *= -1;
                }
            }
        }
        return currentPosition;
    }
}

abstract class Movement {
    // It counts number of steps within one movement
    protected int passedSteps;
    // It counts number of movements
    protected int counter;

    protected int x;

    Movement(int x) {
        this.x = x;
        this.counter = 0;
        this.passedSteps = 0;
    }

    public void ready() {
        passedSteps = 0;
        counter++;
    }

    abstract public boolean isNextStep();

    public int step() {
        passedSteps++;
        return 1;
    }
}

class MovementOdd extends Movement {
    MovementOdd(int x) {
        super(x);
    }

    public boolean isNextStep() {
        return passedSteps < counter * x;
    }
}

class MovementEven extends Movement {
    MovementEven(int x) {
        super(x);
    }

    public boolean isNextStep() {
        return passedSteps < counter + x;
    }

    public int step() {
        // even movements goes in backward direction
        return super.step() * -1;
    }
}

- Anton October 25, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Main {
    public static int x = 3;
    public static int y = 400;
    public static int totalSteps = 500;

    public static void main(String[] args) {
        Robot robot = new Robot();
        int position = robot.go(x, y, totalSteps);
        System.out.println(new StringBuilder("x = ").append(x).append("; y = ").append(y).append("; totalSteps = ")
                .append(totalSteps).append("; Result: ").append(position).toString());
    }
}

class Robot {
    public Robot() {}

    public int go(int x, int y, int totalSteps) {
        if ( x < 0 || y < 0 ) {
            throw new IllegalArgumentException("Robot cannot move negative number of steps, but at least one of input parameters is negative.");
        }
        if (totalSteps <= 0) {
            return 0;
        }
        int currentPosition = 0;
        int currentDirection = 1;
        int totalStepsPassed = 0;
        Movement[] movements = {new MovementEven(x), new MovementOdd(x)};
        int i = 1;

        while (totalStepsPassed < totalSteps) {
            Movement movement = movements[i++ % movements.length];
            movement.ready();
            while(movement.isNextStep() && totalStepsPassed < totalSteps) {
                currentPosition += movement.step() * currentDirection;
                totalStepsPassed++;
                if (totalStepsPassed == y) {
                    currentDirection *= -1;
                }
            }
        }
        return currentPosition;
    }
}

abstract class Movement {
    // It counts number of steps within one movement
    protected int passedSteps;
    // It counts number of movements
    protected int counter;

    protected int x;

    Movement(int x) {
        this.x = x;
        this.counter = 0;
        this.passedSteps = 0;
    }

    public void ready() {
        passedSteps = 0;
        counter++;
    }

    abstract public boolean isNextStep();

    public int step() {
        passedSteps++;
        return 1;
    }
}

class MovementOdd extends Movement {
    MovementOdd(int x) {
        super(x);
    }

    public boolean isNextStep() {
        return passedSteps < counter * x;
    }
}

class MovementEven extends Movement {
    MovementEven(int x) {
        super(x);
    }

    public boolean isNextStep() {
        return passedSteps < counter + x;
    }

    public int step() {
        // even movements goes in backward direction
        return super.step() * -1;
    }
}

- Anton October 25, 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