Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Software Coding: Rock Paper Scissors
00:00
5 left

Software Coding: Rock Paper Scissors

EasyPython

Problem

For a ValueMomentum coding assessment simulator, process a sequence of Rock Paper Scissors rounds between two players. For each round, determine whether Player 1 wins, Player 2 wins, or the round is a draw, then return the complete result sequence and cumulative scores.

Formal Specification

Implement rock_paper_scissors(player1, player2), where player1 and player2 are arrays of equal length containing only the strings "rock", "paper", or "scissors". Return a dictionary with these keys:

  • results: an array containing "P1", "P2", or "Draw" for each round
  • player1_wins: the number of rounds won by Player 1
  • player2_wins: the number of rounds won by Player 2
  • draws: the number of drawn rounds
  • winner: "Player 1", "Player 2", or "Draw" based on cumulative scores

Use the standard rules: rock beats scissors, scissors beats paper, and paper beats rock. The winner is determined by a single pass through the rounds.

Constraints

  • 1 <= len(player1) = len(player2) <= 10^5
  • Every move is one of "rock", "paper", or "scissors"
  • Input arrays are guaranteed to have equal lengths

Function Signature

def rock_paper_scissors(player1, player2):
Interviewer

Your question is Software Coding: Rock Paper Scissors. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.