Given the following code: class Asset { id: string; companyId: string; body: any; public equals(asset: Asset): boolean { return this.companyId == asset.companyId && this.id == asset.id; } } const diffUpdateAssets = (apiAssets: Asset[], dbAssets: Asset[]): Asset[] => { return apiAssets.filter( (asset: Asset) => dbAssets.find(asset.equals) ); }; const diffInsertAssets = (apiAssets: Asset[], dbAssets: Asset[], Map map): Asset[] => { return apiAssets.filter( (asset: Asset) => !dbAssets.find(asset.equals) ); }; const diffDeleteAssets = (apiAssets: Asset[], dbAssets: Asset[]): Asset[] => { return dbAssets.filter( (asset: Asset) => !apiAssets.find(asset.equals) ); }; export const syncAssets = (apiAssets: Asset[], dbAssets: Asset[]) => { return { toInsert: diffInsertAssets(apiAssets, dbAssets), toDelete: diffDeleteAssets(apiAssets, dbAssets), toUpdate: diffUpdateAssets(apiAssets, dbAssets), }; }; 1. Explain what the above code does. What's the time complexity of the code. How it can be improved? how this can be imporved. 2. Simple subquery / inner query SQL question, just learn sub queries. 3. Design question: All of our integrations in DoControl are based on webhooks notifications from the SaaS providers. In order to process those messages we perform a registration of our predefined POST webhook endpoint that will accept those events. Please plan a basic flow which will: a. Receive message from Google Drive b. Enrich its data with an api call performed per each event c. Insert the enriched record to a database.
Sigiloso
1. if (apiAssets.size == dbAssets.size) => O(n2) We can do preprocessing using a set that will go over all the dbAssets ids and insert them to a set. Overall time will be O(4n) ~ O(n). 2. Couldn't add the db screenshots sorry 3. I used a webhook that interacts with an API-Gateway (AWS) and talks with SNS that publish the message to a service (EC2/ECS) and talks to the enrich service and writes the response to S3 and other sources. They want to know that you think of saving the response in S3.