Interview Question for Testing / Quality Assurances






Comment hidden because of low score. Click to expand.
0
of 0 vote

public class robotCord {

public static void main(String[] args) {
// TODO Auto-generated method stub
// int i = 2, j= 4;
// char cf = 'E';
// char[] moves = {'M','M','R','M','M','R','M','R','R','M'};

int i = 3, j= 4;
char cf = 'N';
char[] moves = {'L','M','L','M','L','M','L','M','M'};

for(int m=0; m<moves.length;m++){
if(moves[m]=='M'){
if(cf=='E'){
i++;
}
else if(cf=='W'){
i--;
}
else if(cf=='N'){
j++;
}
else if(cf=='S'){
j--;
}
if(i<0||j<0||i>6||j>7){
System.out.println("Invalid Move");
break;
}
}
else if(moves[m]=='L'){
if(cf=='E'){
cf='N';
}
else if(cf=='W'){
cf='S';
}
else if(cf=='N'){
cf='W';
}
else if(cf=='S'){
cf='E';
}
}else if(moves[m]=='R'){
if(cf=='E'){
cf='S';
}
else if(cf=='W'){
cf='N';
}
else if(cf=='N'){
cf='E';
}
else if(cf=='S'){
cf='W';
}
}
}

System.out.println("Results: "+i+" "+j+" "+cf);

}

}

- Srinidhi June 10, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class robotCord {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
//		int i = 2, j= 4;
//		char cf = 'E';
//		char[] moves = {'M','M','R','M','M','R','M','R','R','M'};
		
		int i = 3, j= 4;
		char cf = 'N';
		char[] moves = {'L','M','L','M','L','M','L','M','M'};

		for(int m=0; m<moves.length;m++){
			if(moves[m]=='M'){
				if(cf=='E'){
					i++;
				}
				else if(cf=='W'){
					i--;
				}
				else if(cf=='N'){
					j++;
				}
				else if(cf=='S'){
					j--;
				}
				if(i<0||j<0||i>6||j>7){
					System.out.println("Invalid Move");
					break;
				}
			}
			else if(moves[m]=='L'){
				if(cf=='E'){
					cf='N';
				}
				else if(cf=='W'){
					cf='S';
				}
				else if(cf=='N'){
					cf='W';
				}
				else if(cf=='S'){
					cf='E';
				}
			}else if(moves[m]=='R'){
				if(cf=='E'){
					cf='S';
				}
				else if(cf=='W'){
					cf='N';
				}
				else if(cf=='N'){
					cf='E';
				}
				else if(cf=='S'){
					cf='W';
				}
			}
		}
		
		System.out.println("Results: "+i+" "+j+" "+cf);

	}

}

- Srinidhi June 10, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class PointMove
{
	public static char curDirection(char a, char b){
		char newDirection=a;
		switch(a){
			case 'N': if (b == 'L'){
						newDirection = 'W';
						}else{
							newDirection = 'E';
						}
						break;
			case 'E': if (b == 'L'){
						newDirection = 'N';
						}else{
							newDirection = 'S';
						}
						break;
			case 'S': if (b == 'L'){
						newDirection = 'E';
						}else{
							newDirection = 'W';
						}
						break;
			case 'W': if (b == 'L'){
						newDirection = 'S';
						}else{
							newDirection = 'N';
						}	
						break;
		}
		return newDirection;
	}
	public static int move (int a, char b,int limit){
		if (b =='N'){
			return (a+1)%limit;
		}
		if ( b == 'E'){
			return (a+1)%limit;
		}
		if (b =='W'){
			return (a-1)%limit;
		}
		else{
			return (a-1)%limit;
		}
	}
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		int minX=0,minY=0;
		Scanner sc = new Scanner(System.in);
		int maxX= sc.nextInt();
		int maxY= sc.nextInt();
		char curmove;
		int currX= sc.nextInt();
		int currY=sc.nextInt();
		char currentDirection= sc.nextLine().charAt(1);
		String moves= sc.nextLine();
		for(int i =0; i< moves.length(); i++){
			curmove=moves.charAt(i);
			if (curmove == 'M'){
				if (currentDirection == 'E' || currentDirection =='W'){
					currX=move(currX,currentDirection,maxX);	
				}else{
					currY=move(currY,currentDirection,maxY);
				} 
			}
			else{
				currentDirection=curDirection(currentDirection,curmove);
			}
		}
		
		//System.out.println(currentDirection);;
		//curDirection('N','L');
		System.out.println(currX+" "+currY+ " "+ currentDirection);
	}
}

- shrinidhi kanchi April 15, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class PointMove
{
	public static char curDirection(char a, char b){
		char newDirection=a;
		switch(a){
			case 'N': if (b == 'L'){
						newDirection = 'W';
						}else{
							newDirection = 'E';
						}
						break;
			case 'E': if (b == 'L'){
						newDirection = 'N';
						}else{
							newDirection = 'S';
						}
						break;
			case 'S': if (b == 'L'){
						newDirection = 'E';
						}else{
							newDirection = 'W';
						}
						break;
			case 'W': if (b == 'L'){
						newDirection = 'S';
						}else{
							newDirection = 'N';
						}	
						break;
		}
		return newDirection;
	}
	public static int move (int a, char b,int limit){
		if (b =='N'){
			return (a+1)%limit;
		}
		if ( b == 'E'){
			return (a+1)%limit;
		}
		if (b =='W'){
			return (a-1)%limit;
		}
		else{
			return (a-1)%limit;
		}
	}
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		int minX=0,minY=0;
		Scanner sc = new Scanner(System.in);
		int maxX= sc.nextInt();
		int maxY= sc.nextInt();
		char curmove;
		int currX= sc.nextInt();
		int currY=sc.nextInt();
		char currentDirection= sc.nextLine().charAt(1);
		String moves= sc.nextLine();
		for(int i =0; i< moves.length(); i++){
			curmove=moves.charAt(i);
			if (curmove == 'M'){
				if (currentDirection == 'E' || currentDirection =='W'){
					currX=move(currX,currentDirection,maxX);	
				}else{
					currY=move(currY,currentDirection,maxY);
				} 
			}
			else{
				currentDirection=curDirection(currentDirection,curmove);
			}
		}
		
		//System.out.println(currentDirection);;
		//curDirection('N','L');
		System.out.println(currX+" "+currY+ " "+ currentDirection);
	}

}

- Anonymous April 15, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class PointMove
{
	public static char curDirection(char a, char b){
		char newDirection=a;
		switch(a){
			case 'N': if (b == 'L'){
						newDirection = 'W';
						}else{
							newDirection = 'E';
						}
						break;
			case 'E': if (b == 'L'){
						newDirection = 'N';
						}else{
							newDirection = 'S';
						}
						break;
			case 'S': if (b == 'L'){
						newDirection = 'E';
						}else{
							newDirection = 'W';
						}
						break;
			case 'W': if (b == 'L'){
						newDirection = 'S';
						}else{
							newDirection = 'N';
						}	
						break;
		}
		return newDirection;
	}
	public static int move (int a, char b,int limit){
		if (b =='N'){
			return (a+1)%limit;
		}
		if ( b == 'E'){
			return (a+1)%limit;
		}
		if (b =='W'){
			return (a-1)%limit;
		}
		else{
			return (a-1)%limit;
		}
	}
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		int minX=0,minY=0;
		Scanner sc = new Scanner(System.in);
		int maxX= sc.nextInt();
		int maxY= sc.nextInt();
		char curmove;
		int currX= sc.nextInt();
		int currY=sc.nextInt();
		char currentDirection= sc.nextLine().charAt(1);
		String moves= sc.nextLine();
		for(int i =0; i< moves.length(); i++){
			curmove=moves.charAt(i);
			if (curmove == 'M'){
				if (currentDirection == 'E' || currentDirection =='W'){
					currX=move(currX,currentDirection,maxX);	
				}else{
					currY=move(currY,currentDirection,maxY);
				} 
			}
			else{
				currentDirection=curDirection(currentDirection,curmove);
			}
		}
		
		//System.out.println(currentDirection);;
		//curDirection('N','L');
		System.out.println(currX+" "+currY+ " "+ currentDirection);
	}
}

- shrinidhi kanchi April 15, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class PointMove
{
	public static char curDirection(char a, char b){
		char newDirection=a;
		switch(a){
			case 'N': if (b == 'L'){
						newDirection = 'W';
						}else{
							newDirection = 'E';
						}
						break;
			case 'E': if (b == 'L'){
						newDirection = 'N';
						}else{
							newDirection = 'S';
						}
						break;
			case 'S': if (b == 'L'){
						newDirection = 'E';
						}else{
							newDirection = 'W';
						}
						break;
			case 'W': if (b == 'L'){
						newDirection = 'S';
						}else{
							newDirection = 'N';
						}	
						break;
		}
		return newDirection;
	}
	public static int move (int a, char b,int limit){
		if (b =='N'){
			return (a+1)%limit;
		}
		if ( b == 'E'){
			return (a+1)%limit;
		}
		if (b =='W'){
			return (a-1)%limit;
		}
		else{
			return (a-1)%limit;
		}
	}
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		int minX=0,minY=0;
		Scanner sc = new Scanner(System.in);
		int maxX= sc.nextInt();
		int maxY= sc.nextInt();
		char curmove;
		int currX= sc.nextInt();
		int currY=sc.nextInt();
		char currentDirection= sc.nextLine().charAt(1);
		String moves= sc.nextLine();
		for(int i =0; i< moves.length(); i++){
			curmove=moves.charAt(i);
			if (curmove == 'M'){
				if (currentDirection == 'E' || currentDirection =='W'){
					currX=move(currX,currentDirection,maxX);	
				}else{
					currY=move(currY,currentDirection,maxY);
				} 
			}
			else{
				currentDirection=curDirection(currentDirection,curmove);
			}
		}
		
		//System.out.println(currentDirection);;
		//curDirection('N','L');
		System.out.println(currX+" "+currY+ " "+ currentDirection);
	}
}

- shrinidhi kanchi April 15, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class PointMove
{
public static char curDirection(char a, char b){
char newDirection=a;
switch(a){
case 'N': if (b == 'L'){
newDirection = 'W';
}else{
newDirection = 'E';
}
break;
case 'E': if (b == 'L'){
newDirection = 'N';
}else{
newDirection = 'S';
}
break;
case 'S': if (b == 'L'){
newDirection = 'E';
}else{
newDirection = 'W';
}
break;
case 'W': if (b == 'L'){
newDirection = 'S';
}else{
newDirection = 'N';
}
break;
}
return newDirection;
}
public static int move (int a, char b,int limit){
if (b =='N'){
return (a+1)%limit;
}
if ( b == 'E'){
return (a+1)%limit;
}
if (b =='W'){
return (a-1)%limit;
}
else{
return (a-1)%limit;
}
}
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
int minX=0,minY=0;
Scanner sc = new Scanner(System.in);
int maxX= sc.nextInt();
int maxY= sc.nextInt();
char curmove;
int currX= sc.nextInt();
int currY=sc.nextInt();
char currentDirection= sc.nextLine().charAt(1);
String moves= sc.nextLine();
for(int i =0; i< moves.length(); i++){
curmove=moves.charAt(i);
if (curmove == 'M'){
if (currentDirection == 'E' || currentDirection =='W'){
currX=move(currX,currentDirection,maxX);
}else{
currY=move(currY,currentDirection,maxY);
}
}
else{
currentDirection=curDirection(currentDirection,curmove);
}
}

//System.out.println(currentDirection);;
//curDirection('N','L');
System.out.println(currX+" "+currY+ " "+ currentDirection);
}
}

- shrinidhi kanchi April 15, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class PointMove
{
	public static char curDirection(char a, char b){
		char newDirection=a;
		switch(a){
			case 'N': if (b == 'L'){
						newDirection = 'W';
						}else{
							newDirection = 'E';
						}
						break;
			case 'E': if (b == 'L'){
						newDirection = 'N';
						}else{
							newDirection = 'S';
						}
						break;
			case 'S': if (b == 'L'){
						newDirection = 'E';
						}else{
							newDirection = 'W';
						}
						break;
			case 'W': if (b == 'L'){
						newDirection = 'S';
						}else{
							newDirection = 'N';
						}	
						break;
		}
		return newDirection;
	}
	public static int move (int a, char b,int limit){
		if (b =='N'){
			return (a+1)%limit;
		}
		if ( b == 'E'){
			return (a+1)%limit;
		}
		if (b =='W'){
			return (a-1)%limit;
		}
		else{
			return (a-1)%limit;
		}
	}
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		int minX=0,minY=0;
		Scanner sc = new Scanner(System.in);
		int maxX= sc.nextInt();
		int maxY= sc.nextInt();
		char curmove;
		int currX= sc.nextInt();
		int currY=sc.nextInt();
		char currentDirection= sc.nextLine().charAt(1);
		String moves= sc.nextLine();
		for(int i =0; i< moves.length(); i++){
			curmove=moves.charAt(i);
			if (curmove == 'M'){
				if (currentDirection == 'E' || currentDirection =='W'){
					currX=move(currX,currentDirection,maxX);	
				}else{
					currY=move(currY,currentDirection,maxY);
				} 
			}
			else{
				currentDirection=curDirection(currentDirection,curmove);
			}
		}
		
		//System.out.println(currentDirection);;
		//curDirection('N','L');
		System.out.println(currX+" "+currY+ " "+ currentDirection);
	}
}

- shrinidhi kanchi April 15, 2017 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More