Professional Documents
Culture Documents
APPracticeTest3 2
APPracticeTest3 2
////// 1 A
//////// 1 B
///// Problem 2
////// Problem 3
////// 3 A
///// 3 B
/// 4A
if(dir == 1)
{
if(lane == hwy.length - 1)
{
return false;
}
for(int i = lane + dir; i < hwy.length; i+=dir)
{
if(hwy[lane][x] == 1)
{
return false;
}
} Use only one while loop instead of
return true;
} splitting into 2 different loops,
else makes code much more efficient.
{
if(lane == 0)
{
return false;
}
for(int i = lane + dir; i > 0; i+=dir)
{
if(hwy[lane][x] == 1)
{
return false;
}
}
return true;
}
////// 4 B