Skip to main content

Grocery Store coding challenge

·547 words·3 mins

This coding challenge is the first of a series I will be posting for TypeScript & Golang, although it can be completed in other languages. As these are used for internal recruitment purposes, I recommend that you keep repositories with this challenge private.

Grocery Store #

A grocery store needs to prepare updates for two systems every night at 12:00 AM. The systems consume data in their own proprietary formats, one is already generated and needs to be updated and the other needs to be manually generated.

The first system is used for stock ordering. It needs to know how many products have been consumed throughout the day so that it can generate orders for the store. This data is formatted as XML.

The second system is used for promotions to customers. It needs to know what products each customer purchased. It will only receive information about customers who used their customer loyalty card when ordering. This data is formatted as JSON.

The orders for the day are available in a CSV. Each order contains the order ID, department, product & customer ID (if available).

Downloads #

TypeScript starter kit #

If you’re doing this challenge in TypeScript, please consider taking advantage of the starting kit available here. This kit includes TypeScript, Jest, eslint & prettier already setup & ready to go.

If you are doing the challenge for Coles, please use the starter kit.

Challenge #

Part 1: Customer Order Grouping #

For each customer that made a purchase on the day, group any orders together by their customer ID only including the products purchased & the quantity of each product purchased.

Do not include any orders that did not include a customer ID.

Write this JSON output to a file named summaries/GroupedOrders.json.

Treat the Customers.json file like a database — not all customers in the Customers.json file would have made a purchase that day, and when reading from the file consider memory efficient approaches.

Part 2: Updating Stock #

The Stock.xml file includes the quantity of each item purchased that day & it is incorrect until updated from today’s orders. For each order, update the corresponding quantities in the Stock.xml file.

Remove any duplicates & add products if they do not exist.

The updated Stock should be output to summaries/Stock.xml.

Considerations #

  1. Be memory efficient — although this challenge only has ~3000 total records, in the real world databases can contain trillions of records.
  2. Treat the filesystem like a database — consider IOPS & the impact of many write operations at once.
  3. Use asynchronous fs methods if you’re doing the challenge in TypeScript.
  4. Consider scalable coding — in an interview you may be asked to expand on the current challenge with new components or data.
  5. Keep it DRY — don’t repeat yourself. Use tests, avoid copying logic.
  6. Have fun. Even if you don’t get to the next round, you’re learning new things.

Submission #

When preparing this challenge for submission, ensure that your repository is private & you that your reviewer is added as a contributor. If I’m your reviewer, add willhackett.

Commit regularly, although your first attempts may not be ideal it’s good to show progression & may assist in telling a story about how you got to the final product.

Author
Will Hackett
I’m Will, a software engineer and architect based in Melbourne, Australia. I’m currently working at Blinq.