Feldman.Max
BAN USERpublic static void PrintPattern(int n)
{
PrintPatternImpl(n, 1, 1);
}
public static void PrintPatternImpl(int n, int current, int startingNumber)
{
int result=1;
if (n >= current)
{
for (int i = 1; i <= current; i++, startingNumber++)
{
result *= startingNumber;
}
Console.WriteLine(result);
PrintPatternImpl(n, current + 1, startingNumber);
Console.WriteLine(result);
}
}
private static string FindTheSmallestSequece(string str, int n)
{
if (n == 0)
return str;
int largest = FindIndexOfTheLargest(str);
string nextIterationStr = Substring(str, largest);
return FindTheSmallestSequece(nextIterationStr, n - 1);
}
private static int FindIndexOfTheLargest(string str)
{
int indexOfMaxValue = 0;
for (int i = 1; i < str.Length; i++)
{
if (str[i] > str[indexOfMaxValue])
indexOfMaxValue = i;
}
return indexOfMaxValue;
}
private static string Substring(string str, int indexToRemove)
{
return str.Substring(0, indexToRemove) + str.Substring(indexToRemove + 1, str.Length-indexToRemove - 1);
}
If there is no space constraint, then go over all the arrays and find the min and max values.
Then, create an array of size max + min only if the min is negative. If the min is positive, then just create an array of size max.
When going over the arrays, then the value of the array is the index in the newly array which you created, and add 1 to the value of the index.
After going over all the arrays, scan once again the created array and check who has value which is more than 1.
Of course, if the min value is negative, then there will be an offset to consider.
- Feldman.Max March 17, 2015