Working as Software consultant than a full time employment is fun and make us up to date. We can see different architectures, coding practices, deployments and other software practices which will definitely help in case we have plans to start own company in future. But the down side is we had to attend interviews more often and there is no guarantee that when our assignment is over the market will be in good condition. Sometimes we may not get the job in the technology we want.
Recently I was attending many interviews. One of those was BarClay card. After 3-4 rounds of interview, I was asked to code a problem in production quality. It assumes 100% test coverage. Below is the problem.
ProblemAn online retail company conducts market research to competitively price their products.Surveyed data contains Product code, Competitor and Price.
The retail company uses a Pricing engine which recommends most frequently occurring price. If multiple prices occur frequently, the least amongst them is chosen.
Products are classified based on parameters like Supply, Demand. Possible values are Low (L), High (H)
If Supply is High and Demand is High, Product is sold at same price as chosen price.
If Supply is Low and Demand is Low, Product is sold at 10 % more than chosen price.
If Supply is Low and Demand is High, Product is sold at 5 % more than chosen price.
If Supply is High and Demand is Low, Product is sold at 5 % less than chosen price.
Prices less than 50% of average price are treated as promotion and not considered.
Prices more than 50% of average price are treated as data errors and not considered.
Input consists of number of products, followed by each Product's supply and demand parameters.
followed by number of surveyed prices, followed by competitor prices.
Output must be recommended price for each product.
Sample inputs and outputsInput 1:
flashdrive H H
ssd L H
flashdrive X 1.0
ssd X 10.0
flashdrive Y 0.9
flashdrive Z 1.1
ssd Y 12.5
mp3player H H
ssd L L
ssd W 11.0
ssd X 12.0
mp3player X 60.0
mp3player Y 20.0
mp3player Z 50.0
ssd V 10.0
ssd Y 11.0
ssd Z 12.0
This has to be completed within 2 days.
There can be different solutions. Below are some point about the one I did.
- For achieving pricing used decorator pattern
- Coded in C#
- Tests done using mUnit.
- Mocks done using Moq library
- Test coverage using ncover
Code is available in the puzzles repo. It took around 6-8 Hrs for me to complete. Please note that they didn't get back to me after I sent this code. So don't just copy paste the code and use for the same puzzle. May be there is something missing.