As programmers, we like to solve problems. In school, we thoroughly enjoy working through solutions for our homework problems. When interviewing for a developer job, we have to solve some complex programming problems (on the spot). As software developers, we still work through complex problems, but suddenly our solutions have more weight because they are solving real business problems. I enjoy solving problems that come from real-world business context; I find that my motivation to solve these problems is greater. Today at work, I came across a problem and worked through a solution that reminded me of a challenging problem one might see at school or in an interview.
Here is the problem:
You are processing potentially thousands of units of inventory and you are writing code to take inventory data from a supplier and syncing it with a distributor. The inventory is comprised of rental properties which have restrictions on specific days that are ‘closed to arrival’ and days that are ‘closed to departure’. Unfortunately, the format that the supplier stores this information is very different from the format that the distributor’s API expects. It is your job to transform this data to be in the proper format for the distributor’s API to handle.
Assume the supplier gives you data for a single unit, and that unit data is comprised of an array of inventory data. Here is the format of the a single inventory data item:
The distributor has a completely different scheme of storing this information. They are expecting an array of date ranges. But those date ranges must also have two fields: closedToArrival and closedToDeparture. The mapping is fairly simple, if allowedArrivalDays for a day of the week is ‘false’, then closedToArrival will be ‘true’ for that date. The main caveat is that each date range must contain only one consistent value for both closedToArrival and closedToDeparture. Here is an example of how the first few date ranges should look (using the example input data above):
If you want updates from me on my future blog posts or on my future projects, please sign up for my email list below!
2 thoughts on “Real-world programming interview question #1”
Your example “solution” mapping seems to assume that 10-3-2015 begins on a Monday (it doesn’t) and doesn’t follow your own rule for mapping for allowedArrival/Departure -> closedToArrival/Departure (your example maps true -> true and false -> false, the opposite of what you said and the names imply).
LikeLiked by 1 person
Thank you for catching that mistake. I have updated it to be an actual solution now haha.