## JP Morgan Interview Question for Applications Developers

Country: United States

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

``````#!/usr/bin/env python

def intersect(r1, r2):
u_d = (r1[0] - r2[0], r1[2] + r1[0] - r2[0])
u_c = (0, r2[2])
v_d = (r1[1] - r2[1], r1[3] + r1[1] - r2[1])
v_c = (0, r2[3])
return interval_intersect(u_d, u_c) and interval_intersect(v_d, v_c)

def interval_intersect(u, v):
return (
(u[0] >= v[0] and u[0] <= v[1]) or
(v[0] >= u[0] and v[0] <= u[1])
)

def run():
data = [
[(1, 1, 1, 1), (-1, -1, 3, 3)],
[(2, 2, 1, 1), (-1, -1, 3, 3)],
[(3, 3, 1, 1), (-1, -1, 3, 3)],
[(-1, -1, 1, 1), (-1, -1, 3, 3)],
[(-2, -2, 1, 1), (-1, -1, 3, 3)],
[(-3, -3, 1, 1), (-1, -1, 3, 3)],
[(-1, 1, 1, 1), (-1, -1, 3, 3)],
[(-2, 2, 1, 1), (-1, -1, 3, 3)],
[(-3, 3, 1, 1), (-1, -1, 3, 3)],
[(1, -1, 1, 1), (-1, -1, 3, 3)],
[(2, -2, 1, 1), (-1, -1, 3, 3)],
[(3, -3, 1, 1), (-1, -1, 3, 3)],
]
for args in data:
print "yes" if intersect(*args) else "no"

if __name__ == '__main__':
run()``````

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

check for every point of the smaller rectangle if it is contained within the bigger rectangle

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

var createArray = function(X, Y, w, h) {
var retArray = [];

// width
for(var i=0; i<=w; i++) {
// height
for(var j=0; j<=h; j++) {
retArray.push( (i+X) +","+ (j+Y) );
}
}
return retArray;
};

var r1 = createArray(1,1,1,1);
var r2 = createArray(-1,-1,3,3);

var l = r1.filter(function(elem) {
return r2.indexOf( elem ) > -1;
}).length;

console.log(l);

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.

### 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.