It was a 90 mins coding round with 2 question.
Question 1: You are given an integer as num and List of strings as blocks.
Blocks have values as Z, X, + and any number.
if element is number - add it to total number
if element X - multiply by 2
if elemnt + - add previous 2 numbers
if element is Z- undo previous calculation
output - return total
Blocks: [5,2,4,Z,X,9,+,+]
num: number of elements in block
O/p: 27
Explanation:
curr Elem 5 , curr Score 5, total score 5
curr Elem -2, curr Score -2. total score 3
curr Elem 4, curr Score 4, total score 7
curr Elem Z, curr Score -2, total score 3 //undo previous calculation and dont consider it henceforth
curr Elem X, curr Score -4, total score -1 // multiply by 2 i.e 2* -2 = -4 and add to previous total i.e -1
curr Elem 9, curr Score 9, total score 8
curr Elem +, curr Score 5, total score 13// add prev 2 score i.e -4+9 = 5 and total = curr score + total
curr elem +, curr SCore 14, total score 27
Final Output = 27
Question 2: given 2 List, find a match
List 1 = List<List> Codes
List 2 = List shoppingCart
Code= {{orange},{apple,apple},{apple,anything,orange}}
shoppingCart= {orange,apple,apple,apple,apricot,,orange}
o/p= true
shoppingCart= {orange,apple,apple,orange,apple,apricot,,orange}
o/p= true
shoppingCart= {orange,apple,apple,orange,appricote,apple,orange,apple}
o/p= false
shoppingCart= {apple,apple,orange,apple,appricote,orange}
o/p= true
order of strings within Codes list matter like if matching apple,anything,orange then this order should be same in the shopping cart list but order of single orange and apple,apple does not matter. also every string elemnt should be considered only once for matching -
shoppingcart={apple,apple,appricote,orange} is false
anything can be any string.