Thor
BAN USER- 1of 1 vote
AnswersGiven a string, find the longest substring without repeating any character.
- Thor in United States| Report Duplicate | Flag | PURGE
Motorola Software Engineer - 1of 1 vote
AnswersGiven a 2D character array of size NxN. Find if there is a path from the cell 'R' to the cell 'T'. You can go left, right, up, down from a cell and you cannot pass through any cell marked with 'X'.
- Thor in United States
Example input:
X__R_X
X_XXX_
______
_XX_XX
XT__X_
Output: true| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 0of 0 votes
AnswersPrint all permutations of a given string.
- Thor in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer
In Java:
private static String buildPath(String name, int width)
{
String path = "";
char c;
int x = 0, y = 0, xChar = 0, yChar = 0, xLastChar = 0, yLastChar = 0;
name = name.toLowerCase();
char lastChar = 'a';
for (int i = 0; i < name.length(); i++)
{
c = name.charAt(i);
xChar = (c - 'a') / width;
yChar = (c - 'a') % width;
xLastChar = (lastChar - 'a') / width;
yLastChar = (lastChar - 'a') % width;
x = xChar - xLastChar;
y = yChar - yLastChar;
if (x > 0)
{
for (; x > 0; x--)
{
path += "d";
}
}
else
{
for (; x < 0; x++)
{
path += "u";
}
}
if (y > 0)
{
for (; y > 0; y--)
{
path += "r";
}
}
else
{
for (; y < 0; y++)
{
path += "l";
}
}
path += "!";
lastChar = c;
}
return path;
}
- Thor November 14, 2016