Each state is unique and can have multiple constituencies. Each constituency can have multiple districts. Each district can have many EVM machines for voting.
addEvm with valid location details should create the state, constituency, and district automatically if they do not already exist.
boolean addEvm(String stateName, String constituencyName, String districtName, String evmId, List<String> candidateNames)
true if the EVM was added.false if the EVM id already exists or the candidate list is empty.boolean registerVoter(String voterId, String stateName, String constituencyName, String districtName)
true if the voter was registered.false if the district does not exist or the voter id is already registered.String castVote(String voterId, String evmId, String candidateName)
"SUCCESS" if the vote is accepted."VOTER_NOT_FOUND" if the voter is not registered."VOTER_ALREADY_VOTED" if the voter has already voted."EVM_NOT_FOUND" if the EVM id does not exist."INVALID_EVM_FOR_VOTER" if the EVM is not in the voter's registered district."CANDIDATE_NOT_FOUND" if the candidate is not available on the EVM.List<String> getConstituencyResult(String stateName, String constituencyName)
"candidateName,voteCount".1 ≤ stateName.length(), constituencyName.length(), districtName.length(), evmId.length(), voterId.length(), candidateName.length() ≤ 501 ≤ candidateNames.size() ≤ 1001 ≤ total number of states ≤ 1001 ≤ total number of constituencies ≤ 10,0001 ≤ total number of districts ≤ 50,0001 ≤ total number of EVMs ≤ 100,0001 ≤ total number of voters ≤ 1,000,0001 ≤ total number of vote attempts ≤ 1,000,000candidateNames will not contain duplicate candidate names for the same EVM.VoterManagementSystem system = new VoterManagementSystem() system.addEvm(stateName = "Bihar", constituencyName = "Patna Sahib", districtName = "Patna Urban", evmId = "EVM-101", candidateNames = List.of("Asha", "Biren", "Chitra")) Output: true system.registerVoter(voterId = "V001", stateName = "Bihar", constituencyName = "Patna Sahib", districtName = "Patna Urban") Output: true system.castVote(voterId = "V001", evmId = "EVM-101", candidateName = "Asha") Output: "SUCCESS" system.getConstituencyResult(stateName = "Bihar", constituencyName = "Patna Sahib") Output: List.of("Asha,1", "Biren,0", "Chitra,0") VoterManagementSystem system = new VoterManagementSystem() system.addEvm(stateName = "Karnataka", constituencyName = "Bengaluru Central", districtName = "MG Road", evmId = "EVM-501", candidateNames = List.of("Dev", "Meera")) Output: true system.registerVoter(voterId = "KA-77", stateName = "Karnataka", constituencyName = "Bengaluru Central", districtName = "MG Road") Output: true system.castVote(voterId = "KA-77", evmId = "EVM-501", candidateName = "Meera") Output: "SUCCESS" system.castVote(voterId = "KA-77", evmId = "EVM-501", candidateName = "Dev") Output: "VOTER_ALREADY_VOTED" system.getConstituencyResult(stateName = "Karnataka", constituencyName = "Bengaluru Central") Output: List.of("Meera,1", "Dev,0") VoterManagementSystem system = new VoterManagementSystem() system.addEvm(stateName = "Maharashtra", constituencyName = "Pune North", districtName = "Shivajinagar", evmId = "EVM-700", candidateNames = List.of("Nitin", "Ravi")) Output: true system.addEvm(stateName = "Maharashtra", constituencyName = "Pune North", districtName = "Kothrud", evmId = "EVM-701", candidateNames = List.of("Nitin", "Ravi")) Output: true system.registerVoter(voterId = "MH-11", stateName = "Maharashtra", constituencyName = "Pune North", districtName = "Kothrud") Output: true system.castVote(voterId = "MH-11", evmId = "EVM-700", candidateName = "Nitin") Output: "INVALID_EVM_FOR_VOTER" system.castVote(voterId = "MH-11", evmId = "EVM-701", candidateName = "Ravi") Output: "SUCCESS" system.getConstituencyResult(stateName = "Maharashtra", constituencyName = "Pune North") Output: List.of("Ravi,1", "Nitin,0")