Hi all ,
Today I gave OA of Amazon .
Coding questions to be solved in 90 mins -
1.[Easy] Given an array of weights ,find the number of swapping required to arrange it in an order such that lightest weight is at the front and heaviest weight is at the last .
I forgot the constraints , it was easy single array traversal .
Swapping can only be done between adjacent element .
Eg1 - input array - [2,4,3,1,6]
Explaination - 6 is already at its place ,
3 <-> 1 --- array changes to --> [2,4,1,3,6] swap_count=1
4 <-> 1 --- array changes to --> [2,1,4,3,6] swap_count=2
2 <-> 1 --- array changes to --> [1,2,4,3,6] swap_count=3
Ouput should be like - [1,2,4,3,6]
Number of operations needed - 3
Eg2 - input array - [3,2,1]
Explaination - 3 <-> 2 --- array changes to --> [2,3,1] swap_count=1
3 <-> 1 --- array changes to --> [2,1,3] swap_count=2
2 <-> 1 --- array changes to --> [1,2,3] swap_count=3
Ouput should be like - [1,2,3]
Number of operations needed - 3 2. [medium+]Given a string , find largest substring not having any prohibited strings .Only return maximum length of possible substring .
Eg - Input string - "FastDeliveryOkayProduct" - prohibited strings - ["yo","eli","eryokay"]
Largest possible string - "kayProduct" - Output Answer-> 11
Constraints - input string length <=10^5 , input string can have uppercase and lowercase alphabets only .
ProhibitedString has only lowercase strings .
Size of prohibited array <=10 .
Size of each prohibited string <=10
Eg2 - Input string - "GoodProductButScrapAfterUse" , Prohibited strings - ["crap","odpro"]
Output string "dProductButScra" -> Output ans -> 15Feel free to comment down your code .
All the best everyone .