Epic Systems Interview Question for Developer Program Engineers


Country: United States




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

public class PermuteRectangle {

	public static void main(String args[] {
		Point sp = new Point(0, 1);
		permuteRectanlge(sp, 30);
	}

	public static void permuteRectanlge(Point startPoint, int area) {
		List<Point> points = listFactors(area);

		for (Point p : points) {
			// flips for e.g. (1,3) --> (3,1)
			if (p.x != p.y) {
				Point p2 = new Point(p.y, p.x);
				rotateRectangleAndPrint(startPoint, p2);
			}
			rotateRectangleAndPrint(startPoint, p);
		}

	}

	// lists all the possible combination for that area
	public static List<Point> listFactors(int area) {
		int j = (int) Math.sqrt(area);
		List<Point> points = new LinkedList<Point>();
		for (int i = 1; i <= j; i++) {
			if (area % i == 0) {
				Point p = new Point(i, area / i);
				points.add(p);
			}
		}
		return points;
	}

	// rotates in 4 directions --> (x,y) , (-x, y) (-x, -y), (x, -y)
	public static void rotateRectangleAndPrint(Point sp, Point ep) {

		Point p = new Point(ep);
		printCords(sp, p);

		p = new Point(-ep.x, ep.y);
		printCords(sp, p);

		p = new Point(-ep.x, -ep.y);
		printCords(sp, p);

		p = new Point(ep.x, -ep.y);
		printCords(sp, p);
	}

	// derives 4 cordinates from start and end points and print them.
	public static void printCords(Point sp, Point ep) {
		// rebase with start point
		ep.x += sp.x;
		ep.y += sp.y;

		Point p1 = sp;
		Point p2 = new Point(sp.x, ep.y);
		Point p3 = ep;
		Point p4 = new Point(ep.x, sp.y);
		
		System.out.println("" + p1 + " " + p2 + " " + p3 + " " + p4);
	}

	private static class Point {
		int x;
		int y;

		Point(int x, int y) {
			this.x = x;
			this.y = y;
		}

		Point(Point p) {
			this.x = p.x;
			this.y = p.y;
		}

		@Override
		public String toString() {
			return String.format("(%d,%d)", x, y);
		}
	}

}

- shrey.haria May 17, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this ans does not consider the case that the rectangle does not rotate 90 degree

- c June 15, 2021 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

area of rectangle = Height x width.
I am assuming that dimensions can only be integeral numbers.
For a given area, factorize it into its prime factors. say S is the set of prime factors.
Calculate power set , there are 2^n-1 such combinations of heights and width that lead to a certain area.

Next up, you just need to rotate the triangle 4 times to get those 4 points.

total complexity is k.2^n where n = |S|

- Joshi of Vatsa. April 30, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Could you please provide your code?

- Brian May 08, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

could you provide your code? Thanks.

- Anonymous May 08, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def rectangle(cord, area):
    ans = []
    for i in range(1, area + 1):
        if area % i == 0:
            ans = []
            x = (i, int(area/i))
            ans.append((cord[0], cord[1]))
            ans.append((cord[0], cord[1] + x[1]))
            ans.append((cord[0] + x[0], cord[0]))
            ans.append((cord[0] + x[0], cord[1] + x[1]))
            print(ans)
            ans = []
            ans.append((cord[0], cord[1])); 
            ans.append((cord[0], cord[1] + x[1]))
            ans.append((cord[0] - x[0], cord[0]))
            ans.append((cord[0] - x[0], cord[1] + x[1]))
            print(ans)
            ans = []
            ans.append((cord[0], cord[1]))
            ans.append((cord[0], cord[1] - x[1]))
            ans.append((cord[0] + x[0], cord[0]))
            ans.append((cord[0] + x[0], cord[1] - x[1]))
            print(ans)
            ans = []
            ans.append((cord[0], cord[1]))
            ans.append((cord[0], cord[1] - x[1]))
            ans.append((cord[0] - x[0], cord[0]))
            ans.append((cord[0] - x[0], cord[1] - x[1]))
            print(ans)

- Anony July 13, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def rectangle(cord, area):
    ans = []
    for i in range(1, area + 1):
        if area % i == 0:
            ans = []
            x = (i, int(area/i))
            ans.append((cord[0], cord[1] + x[1]))
            ans.append((cord[0] + x[0], cord[0]))
            ans.append((cord[0] + x[0], cord[1] + x[1]))
            print(ans)
            ans = []
            ans.append((cord[0], cord[1] + x[1]))
            ans.append((cord[0] - x[0], cord[0]))
            ans.append((cord[0] - x[0], cord[1] + x[1]))
            print(ans)
            ans = []
            ans.append((cord[0], cord[1] - x[1]))
            ans.append((cord[0] + x[0], cord[0]))
            ans.append((cord[0] + x[0], cord[1] - x[1]))
            print(ans)
            ans = []
            ans.append((cord[0], cord[1] - x[1]))
            ans.append((cord[0] - x[0], cord[0]))
            ans.append((cord[0] - x[0], cord[1] - x[1]))
            print(ans)

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

wrote it in python 3.X

def rectangle(cord, area):
ans = []
for i in range(1, area + 1):
if area % i == 0:
ans = []
x = (i, int(area/i))
ans.append((cord[0], cord[1] + x[1]))
ans.append((cord[0] + x[0], cord[0]))
ans.append((cord[0] + x[0], cord[1] + x[1]))
print(ans)
ans = []
ans.append((cord[0], cord[1] + x[1]))
ans.append((cord[0] - x[0], cord[0]))
ans.append((cord[0] - x[0], cord[1] + x[1]))
print(ans)
ans = []
ans.append((cord[0], cord[1] - x[1]))
ans.append((cord[0] + x[0], cord[0]))
ans.append((cord[0] + x[0], cord[1] - x[1]))
print(ans)
ans = []
ans.append((cord[0], cord[1] - x[1]))
ans.append((cord[0] - x[0], cord[0]))
ans.append((cord[0] - x[0], cord[1] - x[1]))
print(ans)

rectangle([0,0], 12)

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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Rectangle_permutations {
public static void main(String[] args) throws IOException {
int x_coord, y_coord, Area;
int x1,x2,x3,y1,y2,y3;
System.out.println("Enter X-coordinate");
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
x_coord = Integer.parseInt(buf.readLine());
System.out.println("Enter Y-coordinate");
BufferedReader buf2 = new BufferedReader(new InputStreamReader(System.in));
y_coord = Integer.parseInt(buf2.readLine());
System.out.println("Enter Area");
BufferedReader buf3 = new BufferedReader(new InputStreamReader(System.in));
Area = Integer.parseInt(buf3.readLine());
x1 = x_coord + Area;
y1 = y_coord;
x2 = x_coord + Area;
y2 = y_coord + 1;
x3 = x_coord;
y3 = y_coord + 1;
System.out.println("("+x1+","+y1+")"+"("+x2+","+y2+")"+"("+x3+","+y3+")");
x1 = x_coord - Area;
y1 = y_coord;
x2 = x_coord - Area;
y2 = y_coord - 1;
x3 = x_coord;
y3 = y_coord - 1;
System.out.println("("+x1+","+y1+")"+"("+x2+","+y2+")"+"("+x3+","+y3+")");
for(int i=2;i<=Area/2;i++)
{
if(Area%i == 0)
{
int j = Area/i;
x1 = x_coord + i;
y1 = y_coord;
x2 = x_coord + i;
y2 = y_coord + j;
x3 = x_coord;
y3 = y_coord + j;
System.out.println("("+x1+","+y1+")"+"("+x2+","+y2+")"+"("+x3+","+y3+")");
x1 = x_coord - i;
y1 = y_coord;
x2 = x_coord - i;
y2 = y_coord - j;
x3 = x_coord;
y3 = y_coord - j;
System.out.println("("+x1+","+y1+")"+"("+x2+","+y2+")"+"("+x3+","+y3+")");
}
}
}
}

- Imran July 21, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public void rectPerm(int x, int y, int A) {
		
		System.out.println("(" +x+","+y+")");
		int [] delta_x = {x,x+A,x,x+A,x-A,x,x-A}; 
		int [] delta_y = {y,y,y+A,y+A,y,y-A,y-A};
		
		for (int i = 0; i < delta_y.length; i++) {
			if(delta_x[i] == x && delta_y[i] == y){
			}else{
				System.out.println("(" +delta_x[i] + ":" + delta_y[i] + ")");
			}
		}

}

- Anonymous January 21, 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