mohd.husn001
BAN USERYou can use an algorithm similar to the quine-mccluskey algorithm for finding prime implicants.
Consider the likematrix above:
players_needed=0
likematrix=
10101
00001
01011
-player 5 is essential so increment the players_needed counter and remove the player column as well as all rows containing that player
players_needed =1
likematrix= empty
-likematrix is empty, therefore we are done. players_needed is 1
Fill the 5 liter bucket, then pour it into the 3 liter until its full. Then you have 2 liters left in the Bigger bucker
- mohd.husn001 June 11, 2013Alright I wrote an answer that does not require an array for storing repeating characters. It only requires 2 pointers and a flag. The algorithm looks at two characters at a time and sets a flag if they are the same. If they are not the same and the flag is unset then we have our first non repeating character.
public static char retFirstNonRep(string vars)
{
int length = vars.Length;
//handle base cases
if (length == 1)
return vars[0];
if (length == 2)
{
if (vars[0] != vars[1])
return vars[0];
}
int a = 0;
int b = 1;
bool rpt = false;
while (b < length)
{
//check matching
if (vars[a] == vars[b])
rpt = true;
else
{
//check repeat flag
if (rpt == false)
return vars[a];
else
rpt = false;
}
//increment ptrs
a++;
b++;
}
b--;
a--;
if (vars[a] != vars[b])
{
return vars[b];
}
return '\0';
}
Do an in-order traversal and see if the elements are sorted. O(n)
- mohd.husn001 September 23, 2014