Skip to content

yasharth2004/Quiz_LeaderBoard_System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quiz Leaderboard System - Internship Assignment

Backend integration solution for the quiz validator system.

This application:

  1. Polls validator API exactly 10 times with poll values 0 to 9.
  2. Waits 5 seconds between each poll request (mandatory).
  3. Merges all responses.
  4. Removes duplicate events using key (roundId + participant).
  5. Aggregates total scores per participant.
  6. Builds leaderboard sorted by totalScore descending.
  7. Computes combined total score across all participants.
  8. Submits leaderboard exactly once.

Tech Stack

  • Node.js 18+
  • Native fetch (no external dependencies)

Project Structure

.
├── .env.example
├── package.json
├── README.md
└── src
		├── config.js
		├── index.js
		├── quizLeaderboard.js
		└── validatorClient.js

API Details Implemented

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 }
	]
}

Deduplication Logic

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.

How To Run

  1. Ensure Node.js 18+ is installed.
  2. 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"
  1. Start the app:
npm start

Runtime Behavior

  • 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.

Sample Output (From Verified Run)

{
	"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
}

Complexity

Let N be total collected events across all 10 polls.

  • Deduplication: O(N)
  • Aggregation: O(N)
  • Sorting leaderboard: O(P log P) where P is number of participants
  • Space: O(N) for dedupe map and aggregated structures

Public GitHub Repository Format

Use this format when sharing your submission:

  • https://github.com/your-username/your-repo.git

Example:

  • https://github.com/johndoe/quiz-leaderboard-system.git

Submission Checklist

  • 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.

About

Quiz Leaderboard backend integration: 10 API polls, deduplication by roundId+participant, aggregated leaderboard, and one-time submission.

Topics

Resources

Stars

Watchers

Forks

Contributors