Google Interview Question: Given a set top box: a, b, c,... | Glassdoor

Find your next job here

Interview Question

Software Engineer Interview Los Angeles, CA

Given a set top box: a, b, c, d, e, f, g, h, i, j, k, l, m

 , n, o p, q, r, s, t u, v, w, x, y z Write code to give the character sequence given a word, For example, if the word is "CON", the function will print this: Right//now we're at B Right//now we're at C OK//to select C Down DOwn Right Right OK//to select O Left//now at N OK//to select N note: Be careful when you're at Z. if you go to the right, you will get stuck. Afterwards, the interviewer adds a space to the right of 'Z' to test the code.

Interview Answer

2 Answers



def trace_word(s):
    x = 0
    y = 0
    c = a[y][x]
    print('At ' + c)
    for c in s:
        p = a[y][x]
        while p!=c:
            # find min and max character in the row y
            low = a[y][0]
            high = a[y][len(a[y])-1]
            # in row y?
            if low = len(a):
                    print('Impossible'); return
                print("Down//now we're at " + a[y][x])
            p = a[y][x]
        print('OK//to select ' + c)

if __name__ == '__main__':

idispatch on Apr 17, 2013

public static void printString(String s)
    int cx = 0;
    int cy = 0;
    for (int i = 0; i dy) {
            System.out.print("UP ");
        while (cx > dx) {
            System.out.print("LEFT ");
        while (cy < dy) {
            System.out.print("DOWN ");
        while (cx < dx) {
            System.out.print("RIGHT ");

Rahul on May 4, 2013

Add Answers or Comments

To comment on this, Sign In or Sign Up.