
1. One party people can make another party people lose all his rights in each round.
2. If one person left or we can say the same people left with the right of voting they just can announce the victory.
The first line contains an integer 'T' which denotes the number of test cases or queries to be run.
The first line of each test case contains a single line consisting of the given string ‘STR’
For each test case, print “foolish” if the foolish party wins and “wise” if the wise party wins.
The output of each test case will be printed in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= | STR | <= 5*10^3
STR[i] = [ ‘w’ , ‘f’ ]
Where ‘T’ is the number of test cases, |STR| represents the length of the string and ‘STR’ represents the given string.
Time Limit: 1 sec
Approach: The idea here is to store the string characters in a 2-D array and their rights whether they have still rights or blocked from voting. Now we can run a loop for each of the indexes and check if the element at the other index is of the opposite party and we can block him. Now after this we can check in our 2-D array that if still, someone left with the right he is declared as the winner.
Algorithm is as follows:
Approach: The idea here is to count the number of foolish people and wise people and for each, we store whether they still have the rights to vote or not and push them in a queue. Now we take the help of queue and if that type of people still has the right to vote we blocked the opposite type of people and decrease its count and we push back the current element in the queue else we pop that element from the queue.
In the end, we check which type of people still has some count that is our winner.
Algorithm is as follows: