Instagram
youtube
Facebook

The Minion Game Hackerrank Solution

Mradul Mishra
Table of Contents

Kevin and Stuart want to play the 'The Minion Game'. Game Rules Both players are given the same string, S. Both players have to make substrings using the letters of the string S.

Kevin and Stuart want to play the 'The Minion Game'.

Game Rules

Both players are given the same string, S.
Both players have to make substrings using the letters of the string S.
Stuart has to make words starting with consonants.
Kevin has to make words starting with vowels.
The game ends when both players have made all possible substrings.

Scoring
A player gets +1 point for each occurrence of the substring in the string S.

For Example:
String  = BANANA
Kevin's vowel beginning word = ANA
Here, ANA occurs twice in BANANA. Hence, Kevin will get 2 Points.

For a better understanding, see the image below:

miniongameexample

 

 

 

 

 

 

 

 

 

 

 

Solution 

def minion_game(string):
    # your code goes here
    n = len(string)
    comb = ((n)*(n+1))/2
    count_k = 0
    count_s = 0
    count_k = sum([len(string[i:]) for i in range(len(string)) if string[i] in "AEIOU"])
    count_s = comb - count_k
    
    if count_s == count_k:
        print("Draw")
    elif count_s > count_k:
        print("Stuart", int(count_s) )
    else:
        print("Kevin", int(count_k))

if __name__ == '__main__':
    s = input()
    minion_game(s)

 

Steps Used to solve the problem:

  1. To get the total number of substrings in a string we have used the formula comb = ((n)*(n+1))/2.
  2. After this we used list comprehension to check for all the words which are having vowels.
  3. For each vowel letter the combination of its words would be the number of words that are coming after that, which could be easily found using len(string[i:]).
  4. Once we found all the combinations of words that are vowels, we did the sum of them and stored them in the variable count_k.
  5. To find the count of Stuart we did subtract that with a total number of combinations using count_s = comb - count_k.

 

This was the solution for 'The Minion Game'. A very popular coding problem on Hackerrank.com

If you still face any problem with this solution, please do comment down below.

Add a comment:

Comments:

Antoniofer

Getting it retaliation, like a nymph would should So, how does Tencent’s AI benchmark work? Prime, an AI is foreordained a basic censure from a catalogue of as surplus 1,800 challenges, from edifice quotation visualisations and web apps to making interactive mini-games. Post-haste the AI generates the rules, ArtifactsBench gets to work. It automatically builds and runs the trim in a coffer and sandboxed environment. To mind how the germaneness behaves, it captures a series of screenshots ended time. This allows it to corroboration seeking things like animations, principality changes after a button click, and other unmistakeable panacea feedback. Conclusively, it hands atop of all this asseverate – the original solicitation, the AI’s jurisprudence, and the screenshots – to a Multimodal LLM (MLLM), to feigning as a judge. This MLLM incrustation isn’t de jure giving a carry absent from философема and a substitute alternatively uses a particularized, per-task checklist to swarms the sequel across ten distinct metrics. Scoring includes functionality, purchaser famous for, and the unaltered aesthetic quality. This ensures the scoring is light-complexioned, in conformance, and thorough. The authoritative doubtlessly is, does this automated arbitrate confidently entertain seemly taste? The results propose it does. When the rankings from ArtifactsBench were compared to WebDev Arena, the gold-standard tranny where admissible humans elect on the most a- AI creations, they matched up with a 94.4% consistency. This is a titanic obliterate from older automated benchmarks, which at worst managed hither 69.4% consistency. On complete of this, the framework’s judgments showed across 90% concurrence with licensed if everyday manlike developers. <a href=https://www.artificialintelligence-news.com/>https://www.artificialintelligence-news.com/</a>

Ayush

Can you please tell me why my code only passing 5 test cases? def minion_game(s): # your code goes here l1=(list(s)) Stuart = 0 Kevin = 0 b="" a=[] for i in range(len(s)): for j in s: b = b+j a.append(b) s=s[1:] b="" #print(a) for k in a: if k.startswith(("A","E","I","o","U")): Kevin = Kevin + 1 else: Stuart = Stuart+1 if Kevin > Stuart: print("Kevin",Kevin) elif Stuart>Kevin: print("Stuart", Stuart) else: print("Draw") if __name__ == '__main__': s = input() minion_game(s)

Swati Rani

Your code did not execute within the time limits. Please optimize your code. For more information on execution time limits, refer to the environment page

Harsh Tripathi

c

Shaurya

You do not need to read any input in this challenge. Output Format Print Hello, World! to stdout. Sample Output 0 Hello, World!