Backend integration solution for the quiz validator system.
This application:
- Polls validator API exactly 10 times with poll values 0 to 9.
- Waits 5 seconds between each poll request (mandatory).
- Merges all responses.
- Removes duplicate events using key
(roundId + participant). - Aggregates total scores per participant.
- Builds leaderboard sorted by
totalScoredescending. - Computes combined total score across all participants.
- Submits leaderboard exactly once.
- Node.js 18+
- Native
fetch(no external dependencies)
.
├── .env.example
├── package.json
├── README.md
└── src
├── config.js
├── index.js
├── quizLeaderboard.js
└── validatorClient.js
Base URL:
https://devapigw.vidalhealthtpa.com/srm-quiz-task
Polling API:
GET /quiz/messages?regNo=<REG_NO>&poll=<0..9>- Response shape used:
{
"regNo": "2024CS101",
"setId": "SET_1",
"pollIndex": 0,
"events": [
{ "roundId": "R1", "participant": "Alice", "score": 10 },
{ "roundId": "R1", "participant": "Bob", "score": 20 }
]
}Submission API:
POST /quiz/submit- Payload:
{
"regNo": "2024CS101",
"leaderboard": [
{ "participant": "Alice", "totalScore": 100 },
{ "participant": "Bob", "totalScore": 120 }
]
}Duplicate protection key:
dedupeKey = roundId + "::" + participant
Why this works:
- The same event can reappear in later polls.
- For each
(roundId, participant)pair, only the first occurrence is counted. - This prevents inflated totals.
- Ensure Node.js 18+ is installed.
- Set environment variables:
export REG_NO="2024CS101"
export BASE_URL="https://devapigw.vidalhealthtpa.com/srm-quiz-task"
export API_KEY=""
export AUTH_TOKEN=""
export POLL_COUNT="10"- Start the app:
npm start- Poll requests are executed in this exact order:
poll=0,1,2,3,4,5,6,7,8,9. - A 5-second delay is enforced between consecutive poll requests.
- Final output prints:
- computed leaderboard
- computed total score
- submission response from validator
- Submission call is guarded to run once per execution.
{
"leaderboard": [
{ "participant": "Bob", "totalScore": 295 },
{ "participant": "Alice", "totalScore": 280 },
{ "participant": "Charlie", "totalScore": 260 }
],
"totalScore": 835
}Submission response observed:
{
"regNo": "2024CS101",
"totalPollsMade": 141,
"submittedTotal": 835,
"attemptCount": 7
}Let N be total collected events across all 10 polls.
- Deduplication:
O(N) - Aggregation:
O(N) - Sorting leaderboard:
O(P log P)wherePis number of participants - Space:
O(N)for dedupe map and aggregated structures
Use this format when sharing your submission:
https://github.com/your-username/your-repo.git
Example:
https://github.com/johndoe/quiz-leaderboard-system.git
- Code pushed to a public GitHub repository.
- Detailed README included (this file).
- Poll count exactly 10 with poll values 0 to 9.
- Mandatory 5-second delay implemented.
- Duplicate events handled correctly.
- Leaderboard and total score computed correctly.
- Submission API called once.