C3.ai Interview Question: 1) Program to print 10 * 10 m... | Glassdoor

Interview Question

Software Engineer Interview

1) Program to print 10 * 10 multiplication table

  2) http://www.geeksforgeeks.org/find-possible-words-phone-digits/
Answer

Interview Answer

2 Answers

0

If you can use Numpy or Pandas, this becomes extraordinarily simple:

row = range(1, 11)
column = range(1, 11)
data = [c * r for c in column for r in row]
mat = np.array(data).reshape(10, 10)
print mat
df = pd.DataFrame(mat, columns=column, index=row)
print df

Ajay on Sep 14, 2016
0

Second question answer utilizing itertools for phone number permutations:

    phone_dict = {'2': 'abc', '3': 'def', '4': 'ghi',
    '5': 'jkl', '6': 'mno', '7': 'pqr', '8': 'tuv',
    '9': 'wxyz'}
    def word_numbers(pn):
        pn = str(pn)
        ret = ['']
        for char in pn:
            letters = phone_dict.get(char, '')
            ret = [prefix+letter for prefix in ret for letter in letters]
        return ret
    digits = '123456789'
    phone_numbers = []
    for val in permutations(digits, 7):
        phone_numbers.append(''.join(val))
    word_list = []
    for number in phone_numbers:
        word_list.append(word_numbers(number))

Ajay on Sep 14, 2016

Add Answers or Comments

To comment on this, Sign In or Sign Up.