hi, let Avik connect you.


** You can give your thought about this content and request modifications if needed from Ask For Modifications page. Thank You.

** You can check all the posts on the Posts page.

** More about me in the About Me section.

Slot Game


  • Approach:

    1. Run a loop through the end of the string.

    2. Check if any of the characters matches both original and the guess.

    3. If matches then changed them into a different character than possible characters. And added 2 with points.

    4. Then checked for the matched character in the other characters of guess for the rest of the characters of the original.

    5. If matches added 1 with points.

    6. Returned the points.


  • Time and Space Complexity:

      • Time Complexity: O(1)

      • Space Complexity: O(1)


Code [C++]

#include <bits/stdc++.h>

int slotScore(string &original, string &guess)

{

int points = 0;

string found = "0000";

for(int i=0; i<4; i++){

if(original[i] == guess[i]){

points += 2;

original[i] = '0';

guess[i] = '0';

}

}

for(int i=0; i<4; i++){

for(int j=0; j<4; j++){

if(original[i] == '0' || guess[j] == '0') continue;

if(original[i] == guess[j]){

original[i] = '0';

guess[j] = '0';

points++;

break;

}

}

}

return points;

}