Barclays Capital Interview Question for Software Engineer / Developers






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

public class temp {
	public static void main(String args[]){
		char[] ar = {'A','R','G','E','N','T','I','N','A'};
		int i = 0;
		int j = ar.length - 1;
		while (i<j) {
			ar[i] ^= ar[j];
			ar[j] ^= ar[i];
			ar[i] ^= ar[j];
			i++;
			j--;
		}
	//	for (i=0;i<ar.length;i++){
	//		System.out.println(ar[i]);
	//	}
	}
}

- Anonymous February 01, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this will not work as 'A' ^ 'A' = 0

- mo March 06, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Just put a condition if they are not same then do XOR swap else continue

- Vishy May 19, 2010 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Even though 'A'^' A' is 0. Please help me understand how it would fail. The swap still happens correctly, doest it?

- teli.vaibhav April 05, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

char temp =' '; is not an object.

public class Test{

	public static void main(String[] args){
	
	
		char[] ar = {'A','R','G','E','N','T','I','N','A'};
		
		int length = ar.length;
		
		char temp =' ';
		
		for(int i=0; i < length/2; i++){
			
			temp = ar[i];
			ar[i] = ar[length -1 -i];
			ar[length -1 -i] = temp;
			
		}
		
		for(int i=0; i < length; i++){
			System.out.print(ar[i]);
		}		
	
	}


}

but yes, bitwise exclusive or satisfies even more strict requirements.

- lwpro2@gmail.com February 02, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

wont his do?

for(int i=0,int j=length-1; i <= j; i++,j--)
                {						         temp = ar[i];			
                 ar[i] = ar[j];			         ar[j] = temp;					         }

- gowtham December 14, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Reverse {
  public static void reverse(char[] arr) {
    for (int i = 0; i < arr.length; i++) {
      swap(arr, i, arr.length - i);
  }

  private static void swap(char[] arr, int i, int j) {
    char temp = arr[i];
    arr[i] = arr[j];
    arr[j] = temp;
  }
}

- zhengyang February 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this loop in zhengyang code will work.
for (int i = 0; i < arr.length /2 ; i++) {
swap(arr, i, arr.length - i -1);
}

- sriram January 17, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Test10 {

	public static void main(String[] args) {
		char[] input = { 'A', 'R', 'G', 'E', 'N', 'T', 'I', 'N', 'A' };
		
		processing(input);
	}

	public static void processing(char[] input) {
		for(int i = input.length-1; i > -1; i--){
			System.out.println(input[i]);
		}
	}

}

- mannerh1 January 19, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static char[] ReverseCharArray(char[] input)
        {
            for (int i = 0, j = input.Length - 1; i < input.Length && i < j; i++, j--) {
                input[i] ^= input[j];
                input[j] ^= input[i];
                input[i] ^= input[j]; }
            return input;
        }

- bjolfr April 04, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static char[] ReverseCharArray(char[] input) {
            for (int i = 0, j = input.Length - 1; i < input.Length && i < j; i++, j--) {
                input[i] ^= input[j];
                input[j] ^= input[i];
                input[i] ^= input[j]; }
            return input;
}

- bjolfr April 04, 2018 | 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