Sunday, 13 May 2018

Microsoft SWE hackerrank questions

Microsoft SWE hackerrank questions


Q1 Given the preorder and inorder traversal of binary tree, find the postorder traversal

INPUT
preorder -> 37, 41, 43, 13, 5, 11, 29, 23, 2, 17, 47, 7, 3, 19, 31
inorder -> 13, 5, 43, 11, 41, 2, 23, 17, 29, 47, 37, 3, 7, 31, 19

Pick one of the choices
A) 5,13,11,43,2,17,23,47,29,41,31,19,7,3,37
B) 5,13,11,43,2,17,23,47,29,41,3,31,19, 7,37
C) 5,13,11,43,47,29,2,17,23,41,3,31,19, 7,37
D) 5,13,11,2,17,23,43,47,29,41,3,31,19, 7,37

Q2 Select the function with highest asymptotic complexity
A) f1(n) = n^0.999999 logn
B) f2(n) = 10000000n
C) f(n) = n^2
D) f3(n) = 1.000001^n

Q3 Calculate the complexity to merge sorted arrays of size k1, k2, k3 ... kn
for e.g.
k1 = 2,5
k2 = 1,4,8
k3 = 3
find complexity to merge k1, k2 and k3. the resulting array will be: R = 1,2,3,4,5,8

A) (k1 + k2 + ... + kn) * n 
B) n * k1 * k2 * k3 * ... * kn
C) (k1 + k2 + ... + kn) * log2n
D) n2

Q4 Sort a integer singly linked of size n in batches of k nodes
Given singly linked list of integers of size n, sort the linked list in increasing order in batches of k nodes.
For e.g. the input singly linked list, L = 4 -> 8 -> 3 -> 9 -> 1 -> 3 -> null and batch of k nodes= 3
Please note that in above e.g. 4->8->3 is first batch of k(3) nodes and 9-> 1->3 is second batch of k(3) nodes.
The output of your function should be: 3 -> 4 -> 8 -> 1 -> 3 -> 9 -> null

Q5 Calculate the count of Combinations given a collection of size n and you need to choose k items from the collection
Given a collection of items of size n, you need to find total count of combinations to select k items from the collection. The formula to calculate the combination is:
nCr = n! / (n-r)! * r!
For e.g. if collection size is. 100 and items to select are 2, then choose k is (100 * 99)/(2 * 1) = 4950

Hit like if these questions help you...!!!

No comments :

Post a Comment