C++ || Yahoo! Sports – Top 10 Fantasy Players – Programming Interview Test (Question 2 of 3)

Print Friendly, PDF & Email

The following is sample code which demonstrates a solution to the Yahoo! Sports programming interview question titled “Top 10 Fantasy Players.”

The test was taken on November 2013 for educational purposes only. Though I completed the test, at the time I had no intention of actually applying for a position, which was for the Junior Backend Test Engineer.

Given two hours, the task was to solve a total of 3 programming questions. The following is question 2 of 3. Questions 1 and 3 can be found here and here.

=== 1. INSTRUCTIONS BEFORE TAKING TEST ===

1. Why take this test? If you get all 3 questions correct you are guaranteed an interview with a Sports Engineer.

2. This is a programming test. Before you begin, Please test your environment with a sample test here.

3. Please make sure you have time free before taking the test. The test usually takes 1 to 2 hours.

4. You are free to choose any language from the list and code.

5. You're expected to write the full code. All inputs are from STDIN and output to STDOUT. If you're using Java, use the classname as 'Solution'.

6. To understand more about the environment, time limits, etc. you can read the FAQ here.

7. You can print to console to debug your code using the appropriate print command for each language (Eg: cout for C++, printf for C, etc.).

=== 2. THE PROBLEM STATEMENT ===

Question 2 / 3 (Top 10 Fantasy Players)

Given a stream of data that contains football player statistical data, where each line represents a single player followed by several stats for that player depicted as:


Player Id,Stat A,Stat B,Stat C,Stat D

Sample Input:

9533,5,45,0,0
8573,10,120,1,0
5352,2,22,0,1
8326,1,3,1,2
9311,12,120,2,1
3343,7,20,220,0
6343,6,18,170,0
7243,2,5,100,1
PRINT

Write a program that displays the top 10 players with the greatest fantasy points based on statistical performance (in descending order of fantasy points) at any point in time. The program should display a single line of output that lists the player id along with the score for each player.

The program should print the following to standard out for each top 10 player when the input is ‘PRINT’ instead of statistical data for a player:


Player Id,Score

Use the following to score players:

2 pts for each Stat A
1 pt for each Stat B
6 pts for each Stat C
-1 pt for each Stat D

NOTE: Player Id will not be repeated. In case of a tie for fantasy points between two or more players, please sort Player Ids in descending order also. For example, output should be similar to this if two or more players (1234, 100 and 202 here) are tied on 12 fantasy points:

1234,12
202,12
100,12

Sample testcases can be downloaded here, which contains sample input and correct output data.

=== 3. TOP 10 FANTASY PLAYERS ===


QUICK NOTES:
The highlighted lines are sections of interest to look out for.

Sample testcases can be downloaded here, which contains sample input and correct output data.

You can read input into the program from a text file using I/O redirection from the Windows command prompt (CMD). Click here if you dont know how to do this.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

Once compiled, you should get this as your output:

Sample Input (input003.txt):

1025,4746,38,406,9
2485,102,0,15,1
3115,1225,6,119,8
PRINT
3116,144,0,12,0
3976,0,0,1,0
4256,5456,39,480,18
4269,10,0,1,0
4319,17,0,1,0
4416,3029,17,293,17
4541,4337,31,385,15
PRINT

Sample Output:

1025,11957
3115,3162
2485,293
4256,13813
1025,11957
4541,11000
4416,7816
3115,3162
3116,360
2485,293
4319,40
4269,26
3976,6

Was this article helpful?
👍 YesNo

Leave a Reply