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

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

0

a=[['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','~','~','~','~']]

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__':
trace_word('con')
#trace_word('cozmo')

idispatch on Apr 17, 2013
1

public static void printString(String s)
{
int cx = 0;
int cy = 0;
for (int i = 0; i dy) {
System.out.print("UP ");
cy--;
}
while (cx &gt; dx) {
System.out.print("LEFT ");
cx--;
}
while (cy &lt; dy) {
System.out.print("DOWN ");
cy++;
}
while (cx &lt; dx) {
System.out.print("RIGHT ");
cx++;
}
System.out.println("PRESS");
}
}

Rahul on May 4, 2013