Skip to content

maxilie/insights-interview

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Topline integration interview project

Thanks for taking the time to interview! We really appreciate it, and we hope to see the best of your work.

Rules

Please do this interview project on your own, without the help of anyone else. With that being said, you are more than welcome to use the internet. Google and Stack Overflow are invaluable tools in our daily lives, and we wouldn't expect you to do your best work without them.

We'd really like to see every part of your development process, so please record your screen while you work.

In addition to writing the code required by the instructions, write down your answers to the questions in the instructions directly in this README file. Most of the questions are open ended, and you don't need to make your code handle the questions below each prompt, but please make sure your code works before moving on to the next question. Clear writing and expressing your ideas is just as valuable as writing great code.

Getting started

Make a fork of this repo on your own GitHub account and then clone it down to your personal computer.

  • Read through the files in the /src directory.
  • Install dependencies for the project with yarn install.
  • Run yarn part-0 to run the /src/min-max-mean-invoice.ts script. Read over the script to get a sense of how we're importing the data from a file. We're cutting some corners to make things easier for this interview. Use this script as a rough guide when writing your own scripts.

Instructions

  1. Implement the top-ten-customers.ts script. Use yarn part-1 to run the script, and paste your output and the answers to the questions below.
  • How does your solution scale with the number of invoices? How about the number of customers?
  1. Implement the customers-by-cohort.ts script. Use yarn part-2 to run the script, and paste your output and the answers to the questions below.
  • How does your solution scale with the number of invoices? How about the number of customers?
  • Does your solution depend on whether the invoice data is sorted?
  1. Implement the revenue-by-cohort.ts script. Use yarn part-3 to run the script, and paste your output and the answers to the questions below.
  • How does your solution scale with the number of invoices? How about the number of customers?
  • Does your solution depend on whether the invoice data is sorted?

Tips

  • All of the questions have a desired output format that can require a lot of string mangling. If you're stuck on the formatting part, move on to the next question and get back to formatting later.
  • Git is your friend. Commit often and use descriptive commit messages. Push your work to GitHub so you don't lose it.
  • Get it working and then make it look good. Don't get lost in the perfect solution before you have a working solution.
  • Write down your responses to all the questions in the prompt before moving on to the next prompt.
  • Include more comments than you would in normal code. This will help us understand your thought process.
  • Take breaks when you need them.
  • You don't have to finish all of the prompts. We prefer thorough, well thought out responses over a complete solution without written responses.

Responses

Please write your responses to the questions in the instructions here. Please indicate any tradeoffs you made.

  1. Output: $ esrun src/top-ten-customers.ts 65: 30846 21: 29686 100: 28979 64: 26915 41: 26807 99: 26778 47: 26326 72: 24977 98: 24595 73: 24422 ✨ Done in 0.13s.

Answers: The solution scales linearly, O(I) with I invoices; and roughly logarithmically, O(C*logC), with C customers. Scalability can be further improved using map/reduce on each task.

All that would be required would be a merge function for each task.

For summation task, the map/reduce would iterate over a batch of invoices and instead of using a blank 'CustomerToAmtMap', it would add new amounts to an existing 'CustomerToAmtMap' which is the output of the previous batch.

For sorting task, the map/reduce would convert a new batch of 'CustomerToAmtMap' to an array, then combine the array with the output of the previous batch, then sort the combined array and return the top 10.

Since there can't be more customers than invoices, the number of invoices will become a bottleneck before the number of customers does. For business purposes, there will be up to a few million customers, but potentially billions of invoices. Thus, the summing task would need to be batched using streams, while the sorting task could probably be done without batching.

  1. Output:
  • $ esrun src/customers-by-cohort.ts
  • 2020-1: 10,11,13,14,15,17,21,23,27,28,30,34,39,40,42,44,51,65,70,72,73,78,80,83,84,89,92,96,98,99
  • 2020-2: 100,20,24,3,32,33,37,41,45,50,56,59,61,67,8,81,82,86
  • 2020-3: 12,19,25,4,47,48,5,55,77,90,93,94
  • 2020-4: 1,16,26,52,57,6,63,64,66,87,88,9,97
  • 2020-5: 18,22,36,38,49,53,74,79,85,95
  • 2020-6: 35,46,60,62,71,75,76
  • 2020-7: 29,58
  • 2020-8: 68,69
  • 2020-9: 43
  • 2020-10: 54,91
  • 2020-11: 2,7
  • 2020-12:
  • 2021-1:
  • 2021-2: 31
  • 2021-3:
  • 2021-4:
  • 2021-5:
  • 2021-6:
  • 2021-7:
  • 2021-8:
  • 2021-9:
  • 2021-10:
  • 2021-11:
  • 2021-12:
  • 2022-1:
  • 2022-2:
  • 2022-3:
  • 2022-4:
  • 2022-5:
  • 2022-6:
  • 2022-7:
  • 2022-8:
  • 2022-9:
  • 2022-10:
  • 2022-11:
  • 2022-12: ✨ Done in 0.14s.

Answers: The solution doesn't require any pre-sorting.

It scales linearly, O(I), given I invoices.

We visit each customer twice, O(C), and also sort up to M arrays for M months, where the total length of all M arrays equal to the number of customers, C. Thus, the solution scales roughly logarithmically, O(C*logC) with the number of customers.

  1. Output: $ esrun src/revenue-by-cohort.ts 2020-1, 2020-2, 2020-3, 2020-4, 2020-5, 2020-6, 2020-7, 2020-8, 2020-9, 2020-10, 2020-11, 2020-12, 2021-1, 2021-2, 2021-3, 2021-4, 2021-5, 2021-6, 2021-7, 2021-8, 2021-9, 2021-10, 2021-11, 2021-12, 2022-1, 2022-2, 2022-3, 2022-4, 2022-5, 2022-6, 2022-7, 2022-8, 2022-9, 2022-10, 2022-11, 2022-12 2020-1: 47544,14299,15089,26052,19599,10712,17445,11709,12017,11262,11282,11984,17916,13013,11048,11662,22799,13339,17209,18581,14662,18579,19921,15751,13461,13986,15371,13616,14594,9188,15315,13310,22829,22654,15167,4882 2020-2: 2556,31149,11149,4522,3215,6833,3877,8236,15256,7758,7159,8861,8510,7206,12929,9933,7279,4861,12529,6724,18475,7772,4625,10961,12134,6396,17554,9480,12503,3576,6084,8564,5862,12533,8010,3812 2020-3: 0,0,24190,0,4974,8545,4731,8372,2841,5846,6246,1756,1007,1328,2928,9392,5037,9378,4121,10891,1580,4535,5954,3062,1080,8205,8145,5254,6403,9348,5433,3039,4443,1526,2984,3281 2020-4: 0,0,0,18900,4921,0,4965,8789,1590,7237,9226,10338,2735,10423,4335,5364,2821,7591,2441,3410,6904,5897,6687,6558,9158,5904,4945,7202,6733,7242,8924,12559,8630,2577,10871,1597 2020-5: 0,0,0,0,19012,6074,4457,5082,5781,6138,2026,4041,4532,1430,7661,4735,4679,0,6809,8307,3100,5346,1211,1935,4406,4933,1215,2992,1357,7850,7231,3151,5231,3202,4017,3014 2020-6: 0,0,0,0,0,13484,7532,2887,6210,2728,3001,4816,7119,1610,5367,7566,1403,5738,2842,0,0,2518,3732,7936,1396,1687,1041,6024,2987,1496,1901,1883,0,3561,1284,1305 2020-7: 0,0,0,0,0,0,3541,1690,0,3178,0,0,2851,1946,1321,0,0,1663,0,0,0,1027,0,0,0,0,0,0,0,1345,0,0,0,1536,1957,0 2020-8: 0,0,0,0,0,0,0,4057,0,0,2621,1420,2316,4388,1724,0,5413,0,0,0,1987,0,0,0,3274,1441,0,0,0,0,3253,0,0,0,1535,2538 2020-9: 0,0,0,0,0,0,0,0,2350,0,0,1602,0,1756,0,0,0,0,0,0,0,0,0,0,0,0,1437,0,0,0,0,0,0,1199,0,0 2020-10: 0,0,0,0,0,0,0,0,0,3002,1266,0,1302,0,0,0,0,1743,0,0,2471,0,0,1799,0,0,0,0,0,0,0,3716,0,0,0,1467 2020-11: 0,0,0,0,0,0,0,0,0,0,2516,1895,0,0,1978,1551,0,1028,3641,0,0,0,0,1989,0,1441,0,1345,1519,4977,0,1026,0,0,2550,1083 2020-12: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 2021-1: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 2021-2: 0,0,0,0,0,0,0,0,0,0,0,0,0,1913,0,0,0,1512,0,0,0,0,1040,0,0,1111,0,0,0,0,0,1936,0,0,0,0 2021-3: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 2021-4: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 2021-5: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 2021-6: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 2021-7: 0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 2022-9: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 2022-10: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 2022-11: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 2022-12: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ✨ Done in 0.16s.

Answers:

No pre-sorting is needed for this solution to work.

The solution scales very similarly to part-2, but with one extra O(N) iteration over number of cohorts (in order to initialize zeros), and one extra O(N) iteration over number of invoices (in order to sum up revenues).

Submitting

To submit your code, send us a link to your repo. Once we confirm that we've downloaded your work, please delete the repo you created so future candidates don't accidentally find your solution.

To submit your screen recording, upload the video to YouTube as "Private" in the "Visibility" section and use the "Share Privately" button to share it with [email protected]. If you'd prefer not to upload the video to YouTube, email [email protected] and we can figure out an alternative.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%