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))

- Anonymous January 10, 2018 | Flag Reply
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))

- hallie January 10, 2018 | Flag Reply
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);

- Anonymous June 21, 2018 | Flag Reply
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);

- Pawan June 21, 2018 | Flag Reply
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);

- pawankorotane June 21, 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