PHP Laravel Developer Assessment v3-1
PHP Laravel Developer Assessment v3-1
This assessment contains 4 PHP related questions, and 3 SQL related questions.
You may use any tools at your disposal to complete these questions.
You should consider cases where different inputs other than that of the question for each of the questions,
we expect different scenarios to be handled and the function will still work accordingly.
Usage of search engines and reference books for code references and syntax is allowed.
However, you are not allowed to search for the direct solution to the questions. You will be disqualified if you
are found cheating (and believe me, we know).
Test Scope:
PHP, MySQL
QUESTION 1
Tony operates a file-sharing website where people can upload and download files.
For the non-members, they cannot download any files of any file type if their last download was 5 seconds
ago.
However, for members, they can download JPEG files twice without any waiting time in between. Only on
the third download, they cannot download any files if their last download was 5 seconds ago.
Both members and non-members cannot download any files of other file types if their last download was 5
seconds ago.
Write a function:
checkDownload($memberType, $fileType)
The function accepts member type and file type as input and returns the response depending on the
aforementioned rules.
If the user tries to download again within the 5 seconds waiting time, it should return a message "Too many
downloads".
The waiting time validation should happen in the backend instead of frontend.
Expected outcomes:
Non-members:
00:00:00 execute checkDownload(‘nonmember’, ‘txt’) returns "Your download is starting..."
00:00:03 execute checkDownload(‘nonmember’, ‘jpeg’) returns "Too many downloads"
Members:
00:00:00 execute checkDownload(‘member’, ‘jpeg’) returns "Your download is starting..."
00:00:03 execute checkDownload(‘member, ‘jpeg’) returns "Your download is starting..."
00:00:05 execute checkDownload(‘member, ‘jpeg’) returns "Too many downloads"
QUESTION 2
Mike and Sam are best friends, they always send encrypted messages with each other. One day you found
out Mike has a set of fixed patterns on his encrypted messages.
● Situation 1:
Mike sends out ‘123456’, Sam receives ‘987654’
Patter: Each original and encrypted characters sum up to 10
● Situation 2:
Mike sends out ‘98642’, Sam receives ‘87531’
Pattern: Each original and encrypted characters add -1
● Situation 3:
Mike sends out ‘31625’, Sam receives ‘64958’
Pattern: Each original and encrypted characters add 3
Write a function:
analyzeMsg($input,$output)
The function accepts an $input and $output and analyzes how the $input is being encrypted into $output.
Expected outcomes:
analyzeMsg(‘123456’,’987654’)
Mike encrypts his message by summing up to 10 to each original character.
analyzeMsg(‘98642’,’87531’)
Mike encrypts his message by adding -1 to each original character.
QUESTION 3
In a school where they have 2 subjects offered to students which are Mathematics and Science. Usually after
a test, the teachers will have to go through every student’s result and write a summary of the students’
performance based on their score. The summary is always written in 2 parts and in the following format.
Part 1:
[ ] has an average score of [ ] from this test.
Part 2:
if the subject score of both student is more than or equal to 50
Overall, [ ] is performing very well in this test.
if the student has either one of the subject score less than 50
However, [ ] is not doing well for [ ] subject.
For example, Andy, a male student, has a score of 60 for Mathematics and 30 for Science, the summary
message will be "Andy has an average score of 45 from this test. However, he is not doing well for the
Science subject."
Write a function:
testSummary($array)
Given that the data are stored in the following format:
Sample data:
['Annie', 'Female', 70, 50]
['Max', 'Male', 20, 70]
['Tom', 'Male', 40, 30]
Expected outcomes:
● Annie has an average score of 60 from this test. Overall, she is performing very well in this test.
● Max has an average score of 45 from this test. However, he is not doing well for Mathematics subject.
● Tom has an average score of 35 from this test. However, he is not doing well for Mathematics and
Science subjects.
QUESTION 4
Tommy is a mobile game developer. He published a gacha game on AppStore. In his game, players can
spend in-game currency to roll for a random equipment item for their characters.
Recently, Tommy introduced a VIP reward system for the player who spend money in-game. The more the
player spent, the higher rank of their VIP. To better reward the VIP, Tommy want to increase the chance of
getting higher rank item when the player's VIP rank increases.
Help Tommy develop a function that can let higher rank VIP to have better chance to get higher rarity item.
Given that:
item_rarity = [1,2,3,4,5] // 1 = common, 5 = legendary
vip_ranks = [vip1,vip2,vip3] // vip1 = lowest rank
Write functions:
Expected Outcomes:
vip1 player have higher chance to get an item in [1,2] rarity
vip2 player have higher chance to get an item in [1,2,3] rarity
vip3 player have higher chance to get an item in [1,2,3,4] rarity
Please note that:
1. Tommy may add more items to item_rarity[]. exp [6, 7, 8]
2. Tommy may add more level to vip_ranks[]. exp [vip4, vip5]
3. Avoid any hardcoded logic that may disallow new entry into item_rarity and vip_ranks
3. You are allowed to make additional assumptions.
QUESTION 5
Given 3 tables in MySQL database as below. This database is from an online store.
TBL_CUSTOMERS
USERID NAME ADDRESS AGE
1 Adam 12, JALAN ABC 25
2 Jane D-12-6 WISMA ABC 40
3 Dylan 12A, SOLOK ABC 16
TBL_TRANSACTIONS
ORDERID TRANSACTION_DATE ITEM QUANTITY UNIT PRICE
1001 2016-11-25 02:00:00 Apple 5 2.45
1002 2016-11-26 16:30:00 Orange 12 0.5
1003 2016-11-26 12:32:00 Pineapple 2 12.00
1004 2016-11-27 07:45:00 Peach 7 6.00
1005 2016-11-28 23:05:00 Durian 1 23.70
TBL_ORDERS
USERID ORDERID
1 1001
2 1003
1 1004
2 1002
1 1005