I came across a interview experience of MIcrosoft, where this question was asked for a senior position and the guy who posted didn't solved it rather discussed his idea with interviewer and he was unsure if he was right or wrong. (He didn't say the idea.)
Here's the problem description :
" Another problem: Guess the next possible words in a sequence.
["A1", "A3", "A5"] extend this sequence to 6 length.
Ans wil be ["A1", "A3", "A5", "A7", "A9", "A11"]
Input can be anything, you need to figure out a sequence and extend it for the required length.
Another ex: ["AB1", "BC3", "CD5"] extend it to 5 length.
Ans will be ["AB1", "BC3", "CD5", "DE7", "EF9"]
Able to provide an approach and had a discussion for possible cases. Not sure if I was correct or wrong as time was up for the interview and we had to end the discussion. "
It took me approx. 1 hour to solve this and it's the best problem I solved till now. (I'm a noob)
[Python 3]
s = input().split() # input sequence
ex = int(input()) # input required length
nums = []
alpha = []
def addalpha(char,num) :
return rev_chars[(chars[char]+num)%26]
chars = {chr(i+ord('A')):(i+1) for i in range(26)}
rev_chars = {a:b for b,a in chars.items()}
for i in s :
temp1 = []
temp2 = []
for c in i :
if c.isdigit() :
temp1.append(c)
else :
temp2.append(c)
nums.append(temp1)
alpha.append(temp2)
nums = [int("".join(i)) for i in nums]
diff = [nums[i]-nums[i-1] for i in range(1,len(nums))]
while(len(nums) != ex) :
nums.append(nums[-1]+diff[0])
nums = [str(i) for i in nums]
adiff_big = []
for i in range(len(alpha[0])) :
adiff_big.append(chars[alpha[1][i]]-chars[alpha[0][i]])
while(len(alpha) != ex) :
sa = []
for i in range((len(alpha[0]))) :
sa.append(addalpha(alpha[-1][i],adiff_big[i]))
alpha.append(sa)
alpha = ["".join(i) for i in alpha]
l = ["".join(i) for i in list(zip(alpha,nums))]
print(l)INPUT :
AA1 BC4 CE7
25
OUTPUT :
['AA1', 'BC4', 'CE7', 'DG10', 'EI13', 'FK16', 'GM19', 'HO22', 'IQ25', 'JS28', 'KU31', 'LW34', 'MY37', 'NA40', 'OC43', 'PE46', 'QG49', 'RI52', 'SK55', 'TM58', 'UO61', 'VQ64', 'WS67', 'XU70', 'YW73']
I got job in TCS DIGITAL through Codevita in 2019 ( still didn't get joining letter ) and I have little Idea about graph, tree, tries and other DSA stuffs ( I'm doing the DSA specialisation from C_O_UR_S_ERA currently). I'm very new to competitive coding. My main focus in my college years was ML,AI, all kind of development stuffs. But now I want to crack google and I've started to LEETCODE for the last 1 week. Can you guys share some tips ? Yesterday in C_oD_E_Fo_r_Ces # 666 div 2 challenge out of 5 I solved 2 complete and 1 partial(minor edge case missed). From looking at my coding style what's your analysis ? I'll be grateful to each one of you for any kind of criticism. I want to get better.