Interview Question for Staff Engineers


Country: India




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

void generatePattern(const int number){
for(int row = 1; row < number ; row++){
for(int column = 1; column <= number; column++){
if(column == 1) {
if(row % 2 == 1 ) cout<<row<<" ";
else cout<<row+1<<" ";
} else if (column == number){
if(row % 2 == 1) cout<<row + 1<<" ";
else cout<<row<<" ";
} else {
cout<<row<<" ";
}
}
cout<<endl;
}
}

- Muhammed Ashiq January 25, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

for (int i = 1; i < n; i++) {
			for (int j = 1; j <= n; j++) {
				if ((i % 2 != 0) && (j != n)) {
					System.out.print(i + " ");
				} else if ((i % 2 != 0) && (j == n)) {
					System.out.print(i + 1 + " ");
				} else if ((i % 2 == 0) && (j != 1)) {
					System.out.print(i + " ");
				} else if ((i % 2 == 0) && (j == 1)) {
					System.out.print(i + 1 + " ");
				}

			}
			System.out.println();
		}

- Viren Pendalwar January 25, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

for (int i = 1; i < n; i++) {
			for (int j = 1; j <= n; j++) {
				if ((i % 2 != 0) && (j != n)) {
					System.out.print(i + " ");
				} else if ((i % 2 != 0) && (j == n)) {
					System.out.print(i + 1 + " ");
				} else if ((i % 2 == 0) && (j != 1)) {
					System.out.print(i + " ");
				} else if ((i % 2 == 0) && (j == 1)) {
					System.out.print(i + 1 + " ");
				}

			}
			System.out.println();
		}

- viren.pendalwar January 25, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

temp = ""
for i in range(1,8):
	if i%2:
		temp += str(i)*7
		temp += str(i+1)
	else:
		temp += str(i+1)
		temp += str(i)*7
	temp += "\n"

print(temp)

- Avinash January 25, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

module.exports = function (n) {
	var S = ''
	for (var i = 1; i < n; ++i) {
		if (i % 2 !== 0) {
			for (var j = 0; j < n - 1; ++j) {
				S += i + ' '
			}
			S += (i + 1)
			S += '\n'
		} else {
			S += (i + 1) + ' '
			for (j = 0; j < n - 1; ++j) {
				S += i + ' '
			}
			S += '\n'
		
		}
	}
	return S
}

- srterpe January 25, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

PHP

function problem3($input) {
  for ($i=1; $i<$input; ++$i) {
    $j=$i;
    for ($k=0; $k<$input; ++$k) {
      if ($j % 2 == 1) {
        if ($k == $input - 1) {
          echo $j+1 . " ";
        } else {
          echo "$j ";
        }
      } else {
        if ($k == 0) {
          echo $j+1 . " ";
        } else {
          echo "$j ";
        }
      }
    }
    echo "\n";
  }
}
problem3(8);

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

void printPattern()
{ 
    
    
    for(int i=1;i<m_n;i++ )
      { 
        
         for(int j=0;j<m_n;j++)
         {
             
           if(i%2!=0){
               if(j==m_n-1)
               {
                 System.out.print((i+1)+" ");  
                 System.out.println();
              
                }else
               {
                  
                  System.out.print(i+" ");
               }
            
           }
             else
             {
             
                 if(j==0)
               {
                 System.out.print((i+1)+" ");  
                
              
                }else
               {
                  
                  System.out.print(i+" ");
                  
                 if(j==m_n-1)
                 {
                   System.out.println();
                 } 
               }
             
             
             }
             
               
        }
          
       }
        
}

- prizkaboom January 26, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String args[])
	{
		
		System.out.println("enter the number of rows");
		Scanner s =new Scanner(System.in);
		int num= s.nextInt();
		
		for (int row = 1; row < num; row++) {
			for (int col = 1; col <= num; col++) {
				if(col==1)
					System.out.print(row);
				else if(col==num)
					System.out.println(1+row);
				else
					System.out.print(row);
			}
		}

- Hyder January 27, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
		
		System.out.println("Enter the number of rows");
		Scanner s =new Scanner(System.in);
		int num= s.nextInt();
		
		for(int j = 1 ;j<num;j++){
			if(j%2 !=0){
				for(int k= 0; k<7; k++){
					System.out.print(j);
				}
				System.out.print(j+1);
			}else{
				System.out.print(j+1);
				for(int k=0; k<7;k++){
					System.out.print(j);
				}
			}
			System.out.println();
		}
		
		
		
		
		
	}

- surendrapandey3788 January 30, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
class pattern
{
public static void main(String args[]){
	int i,n,k,j;
	Scanner sc=new Scanner(System.in);
	System.out.println("enter size:");
	n=sc.nextInt();
	k=1;
	for(i=0;i<n-1;i++)
	{
			if(i%2==0)
			{
				for(j=0;j<n-1;j++)
				{
					System.out.print(k);
				}
				System.out.println(k+1);
			}
			else
			{
				System.out.print(k+1);
				for(j=0;j<n-1;j++)
				{
					System.out.print(k);
				}
				System.out.println();
			}
			k++;
		
	}
}
}

- garima0496 February 04, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public  static void inPutmatx(int n, int l,int i) {
    int j = n;
inputrec(n,l,i);

  }
  private static void inputrec(int n, int l,int i){
    int j=n;
    if (i == l - 1 && j < l) {
      j = j + 1;
      i = 0;
      System.out.print(" " + j);
      System.out.println();
      inPutmatx(j, l,i);
    } else {
      if (j == l) {
        System.out.print(" ");
      } else {
        i = i + 1;
        System.out.print(" " + j);
        inPutmatx(j, l,i);
        //System.out.print(" " + j);
      }
    }
  }

- UdayJoshi February 05, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public  static void inPutmatx(int n, int l,int i) {
    int j = n;
inputrec(n,l,i);

  }
  private static void inputrec(int n, int l,int i){
    int j=n;
    if (i == l - 1 && j < l) {
      j = j + 1;
      i = 0;
      System.out.print(" " + j);
      System.out.println();
      inPutmatx(j, l,i);
    } else {
      if (j == l) {
        System.out.print(" ");
      } else {
        i = i + 1;
        System.out.print(" " + j);
        inPutmatx(j, l,i);
        //System.out.print(" " + j);
      }
    }
  }

- UdayJo February 05, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("size:");
int n=sc.nextInt();
boolean a = true;
for(int i=1;i<n;i++){
if(a){
printTrue(i,n);
a = false;
System.out.println("");
}else{
printFalse(i,n);
a = true;
System.out.println("");
}
}
}

private static void printTrue(int from, int to){
for(int i=1;i<to;i++){
System.out.print(from+" ");
}
System.out.print(from+1+" ");
}
private static void printFalse(int from, int to){
System.out.print(from+1+" ");
for(int i=1;i<to;i++){
System.out.print(from+" ");
}
}

- Andrey D February 13, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		System.out.println("size:");
		int n=sc.nextInt();
		boolean a = true;
		for(int i=1;i<n;i++){
			if(a){
				printTrue(i,n);
				a = false;
				System.out.println("");
			}else{
				printFalse(i,n);
				a = true;
				System.out.println("");
			}
		}
	}
	
	private static void printTrue(int from, int to){
		for(int i=1;i<to;i++){
			System.out.print(from+" ");
		}
		System.out.print(from+1+" ");
	}
	private static void printFalse(int from, int to){
		System.out.print(from+1+" ");
		for(int i=1;i<to;i++){
			System.out.print(from+" ");
		}
	}

- masterresultonline February 13, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String arg[]){

int n = Integer.parseInt(arg[0]);
for(int i =1; i< n; i++){
for(int j =0; j< n; j++){
System.out.print(i
+(j==n-1 && i%2 !=0 ? 1:0)
+(j==0 && i%2 ==0 ? 1:0)
);
}
System.out.println();

}
}

- Jaspreet February 28, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String arg[]){
        
        int n = Integer.parseInt(arg[0]);
        for(int i =1; i< n; i++){
            for(int j =0; j< n; j++){
                System.out.print(i
                        +(j==n-1 && i%2 !=0 ? 1:0)
                        +(j==0 && i%2 ==0 ? 1:0)
                );
            }
           System.out.println();

        }
    }

- Jaspreet February 28, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class NumSeqFormat {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		NumSeqFormat nf = new NumSeqFormat();
		nf.printSeq(8);
	}
	
	public void printSeq(int c){
		
		for(int i=1; i<c;i++){
			int j =1;
			
			if(i%2!=0){
				while(j<c){
				System.out.print(i+" ");
				j++;
				if(j==c){
					System.out.print(i+1);
					System.out.println("");
				}
				}
			}else{
				j=c;
				if(j==c){
					System.out.print(i+1+" ");
					j--;
					}
				while(j>=1){
						System.out.print(i+" ");
                        j--;
					}
				System.out.println("");
			}
			
		}
	}

}

- srinav141 March 05, 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