Вы находитесь на странице: 1из 3

Maven Lab Pte Ltd | ​https://www.mavenlab.

com/

Rules

1. You have ​24 hours ​to implement a solution to this coding test.
2. We will be looking into your solution not only to test whether it is working as expected,
but also to see how you code, so please try your best to craft the most beautiful code
you can!
3. If a particular workflow or boundary condition is not defined in the problem statement
below, what you do is your choice.
4. Please ensure that you follow the syntax and formatting of the output samples.
5. When you have finished, we’ll need you to submit:
a. Your codes
b. A way for us to execute your solution, which could be by:
i. Dockerfile - a preferred method and which will give you extra points in our
eyes!
ii. NodeJS Executable
c. README.md which will contain a brief explanation of your approach and
instructions on where your executables are and/or how to run your solution.
6. Please do not make either your solution or this problem statement publicly available in
any way (e.g. using github or bitbucket or by posting this problem to a blog or forum).

1​ out of 3 pages
Maven Lab Pte Ltd | ​https://www.mavenlab.com/

Problem Statement
There are 10 users with various numbers of data and a certain scheduled timing where they
want them to be processed. At the start of the program’s runtime, it will randomly generate the
number of items for each user (min: 1 / max: 1000000). Each item will also have a random
processing time (min: 1 second / max: 5 seconds). The scheduled timing for each user should
also be randomly generated.

Next, we would like to simulate a processing engine where the 10 users from before can come
in to process their data at different points in time. This engine has 2 threads which can run at
the same time, and to make it fair for all users, they will alternate between the users when
processing the data.

To illustrate; when the scheduled time comes for user A who needs 200000 items to be
processed, and in the middle of processing those, user B who has 10 items comes in to process
their data, the engine should not wait until user A’s items are all processed to work on user B’s,
because it will be unfair to the latter. Instead, the engine should be able to use both 2 threads to
alternate between processing user A’s items and user B’s items. The same principle applies for
when more than two users are trying to use the engine to process their data.

We also require the solution to closely follow the format as defined under ​Expected Result​.

2​ out of 3 pages
Maven Lab Pte Ltd | ​https://www.mavenlab.com/

Expected Result
After user inputs has been randomly generated:
Generated user inputs:
User A: {{number_of_data}} items - scheduled at {{minutes}}:{{seconds}}
User B: {{number_of_data}} items - scheduled at {{minutes}}:{{seconds}}
User C: {{number_of_data}} items - scheduled at {{minutes}}:{{seconds}}
...
User J: {{number_of_data}} items - scheduled at {{minutes}}:{{seconds}}
For example:
Generated user inputs:
User A: 200000 items - scheduled at 00:00
User B: 10 items - scheduled at 00:05
User C: 1000000 items - scheduled at 00:50
...
User J: 2 items - scheduled at 05:00

When the data processing engine is ready and starts to process the data:
Engine starting...
{{minutes}}:{{seconds}} - {{user}} comes in to process {{number_of_data}} items
{{minutes}}:{{seconds}} - Thread {{thread_number}} - {{user}}: start processing
item {{processed_data_value}}
{{minutes}}:{{seconds}} - Thread {{thread_number}} - {{user}}: finished
processing item {{processed_data_value}} (Duration: {{duration_in_seconds}}s)
...
Engine has processed all data.
For example:
Engine starting...
00:00 - User A comes in to process 200000 items
00:00 - Thread 1 - User A: start processing item 1
00:00 - Thread 2 - User A: start processing item 2
00:01 - Thread 1 - User A: finished processing item 1 (Duration: 1s)
00:01 - Thread 1 - User A: start processing item 3
00:03 - Thread 2 - User A: finished processing item 2 (Duration: 3s)
00:03 - Thread 2 - User A: start processing item 4
00:03 - Thread 1 - User A: finished processing item 3 (Duration: 2s)
00:03 - Thread 1 - User A: start processing item 5
00:05 - User B comes in to process 10 items
00:05 - Thread 1 - User A: finished processing item 5 (Duration: 2s)
00:05 - Thread 1 - User B: start processing item 1
00:06 - Thread 2 - User A: finished processing item 4 (Duration: 3s)
00:06 - Thread 2 - User A: start processing item 6
...
Engine has processed all data.

3​ out of 3 pages

Вам также может понравиться