PROBLEM LINK:
DIFFICULTY:
CAKEWALK
PROBLEM:
Given the results of 5 rounds of cricket between India and England, determine the team that has won strictly more matches than the other team (output draw if neither team has scored more than the other).
EXPLANATION:
The problem has a straightforward solution.
Maintain two variables ind_score
and eng_score
, corresponding to the number of matches won by India and England respectively. Both values are initially 0. Then, iterate over the test results,
- increasing
ind_score
by 1 if India won the current match, - increasing
eng_score
by 1 if England won the current match, and - doing nothing if it is a draw (since neither team won the match).
At the end, output
-
INDIA
ifind_score > eng_score
, -
ENGLAND
ifeng_score > ind_score
, and -
DRAW
otherwise.
TIME COMPLEXITY:
O(1)
per test case.
SOLUTIONS:
Editorialist’s solution can be found here
Experimental: For evaluation purposes, please rate the editorial (1 being poor and 5 excellent)
- 1
- 2
- 3
- 4
- 5
0 voters