## Goldman Sachs Interview Question for Software Developers

Country: India
Interview Type: Phone Interview

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

``````test1 = "ULDLLUDL"
test2 = "UP 2xDOWN LEFT 4xRIGHT"

def get_moves(s):
s = s.split(' ')
if len(s) > 1:
return s
else:
return list(s.pop())

def move_robo(x, y, m):
move = m.split('x')
k = 1
if len(move) == 2:
k = int(move.pop(0))
d = move.pop()[0]
if d == 'U':
y += (1 * k)
elif d == 'D':
y -= (1 * k)
elif d == 'L':
x -= (1 * k)
else:
x += (1 * k)
return x, y

def run_robo(s):
moves = get_moves(s)
x, y = 0, 0
for move in moves:
x, y = move_robo(x, y, move)
return x, y

print(run_robo(test1))
print(run_robo(test2))``````

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

``````test1 = "ULDLLUDL"
test2 = "UP 2xDOWN LEFT 4xRIGHT"

def get_moves(s):
s = s.split(' ')
if len(s) > 1:
return s
else:
return list(s.pop())

def move_robo(x, y, m):
move = m.split('x')
k = 1
if len(move) == 2:
k = int(move.pop(0))
d = move.pop()[0]
if d == 'U':
y += (1 * k)
elif d == 'D':
y -= (1 * k)
elif d == 'L':
x -= (1 * k)
else:
x += (1 * k)
return x, y

def run_robo(s):
moves = get_moves(s)
x, y = 0, 0
for move in moves:
x, y = move_robo(x, y, move)
return x, y

print(run_robo(test1))
print(run_robo(test2))``````

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

``````const str = "ULDLLUDL";

const positionName = {
U : 'UP',
D : 'Down',
L : 'LEFT'
};

const postionCounter = new Map();

str.split('').forEach((val, index) => {
if(postionCounter.has(val)){
postionCounter.set(val, postionCounter.get(val) + 1);
}else{
postionCounter.set(val, 1);
}
});

let output = '';
postionCounter.forEach((val, index) => {
output += `\${val}X\${positionName[index]} `;
});

console.log(output);``````

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

``````const str = "ULDLLUDL";
const positionName = {
U : 'UP',
D : 'Down',
L : 'LEFT'
};
const postionCounter = new Map();
str.split('').forEach((val, index) => {
if(postionCounter.has(val)){
postionCounter.set(val, postionCounter.get(val) + 1);
}else{
postionCounter.set(val, 1);
}
});
let output = '';
postionCounter.forEach((val, index) => {
output += `\${val}X\${positionName[index]} `;
});
console.log(output);``````

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

``````const str = "ULDLLUDL";

const positionName = {
U : 'UP',
D : 'Down',
L : 'LEFT'
};

const postionCounter = new Map();

str.split('').forEach((val, index) => {
if(postionCounter.has(val)){
postionCounter.set(val, postionCounter.get(val) + 1);
}else{
postionCounter.set(val, 1);
}
});

let output = '';
postionCounter.forEach((val, index) => {
output += `\${val}X\${positionName[index]} `;
});

console.log(output);``````

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.