Barclays Capital Interview Question for Senior Software Development Engineers


Country: United States




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

no need of O(n^2)
When the universe is finite you can always fall back on counting sort or a modification thereof.
O(n) + constant space

- EK MACHCHAR May 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Test {
public static void main(String[] args) {

char[] charArr ={'a','b','a','a','c','d',' ','a','e','a','c','b','b','f','g',' '};
//remove the duplicate char by ' '
for(int i=0;i<charArr.length;i++){
for(int j=0;j<charArr.length;j++){
if((i!=j)&& charArr[i] != ' ' && charArr[i]==charArr[j]){
charArr[j] = ' ';
}
}
}
// push the blank to end
for(int k=0;k<charArr.length ;k++){
for(int l=k+1;l<charArr.length;l++)
if(charArr[k] == ' ' && charArr[l] != ' ' ){
charArr[k] = charArr[l];
charArr[l] = ' ';
}
}
for(int ii=0;ii<charArr.length;ii++){
System.out.println("-----------: " + charArr[ii]);
}
}

}

Time complexity is O(n^2)

- cCAACc May 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use bit array of size 256.
Do one scan of the give array and while scanning set ar[character] = true.
In second scan, take a charater, check if ar[character] is true, if true, don't do anything, else set it as empty.
In third scan, swap the blank with characters to bring them in the front. To do this, you can use two index one to hold blank position and when other reaches a character swap character and move that until you reach blank that is less than or equal to running index.

- Anonymous May 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1.Easy way is to use any of efficient sorting method(o(nlogn, merge sort)), or any other to sort given array.
2.Then trace array in o(n) to remove duplicates by simply advancing pointer on encounter of previous char.
correct me if I m wrong

- sc May 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

me too

- 11mxian May 30, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void removeDuplicates(){
		
		char[] chArray = {'a','a','b','c','a','b','d','c','c','d','a','a'};
		char[] finalArray = new char[12];
		int k = 0;
		
		System.out.println(chArray);
		for (int i = 0; i < chArray.length ; i++){
			char tmpChar = chArray[i];
			for (int j = i+1; j < chArray.length; j++){
				if (chArray[j] == tmpChar){
					chArray[j] = ' ';
				}
			}
			if (chArray[i] != ' '){
				finalArray[k] = chArray[i];
				k++;
			}
		}
		System.out.println(finalArray);
	}

- Memabo May 20, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<conio.h>
int* merge(int a[],int first1,int first2)
{
int i=0;
int temp;
for(i=first1;i<first2;i++)
{
if(a[i]>a[first2])
{
temp=a[i];
a[i]=a[first2];
a[first2]=temp;
first2++;
}
else if(a[i]==a[first2])
a[i]=0;
}
return a;

}
int* divide(int array[],int first,int last)
{
int mid=((first+last)/2);
int i;
if(first!=last)
{
divide(array,first,mid);
divide(array,mid+1,last);
array=merge(array,first,mid+1);
}
return array;
}
void main()
{
int array[]={2,2,3,6,5,6,7,9,7,9};
int i=0;
int *a;
int *ptr=NULL;
clrscr();
a=divide(array,0,9);
for(i=0;i<10;i++)
{
if(ptr==NULL)
{
if(a[i]==0)
ptr=&a[i];
}
else
{
if(a[i]!=0)
{
*ptr=a[i];
a[i]=0;
ptr++;
}
}
}
for(i=0;i<10;i++)
{
printf("%d\n",a[i]);
}
getch();
}

- parthi May 31, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void removeDupl(char a[]){
		boolean ind[]=new boolean[26];//Used to indicate if the char already exists
		int currIndex=0; //Used to indicate last index of unique chars
		for(int i=0;i<a.length;i++){
			int val=a[i]-'a';
			if(ind[val])//Check in the ind if char already exists
			{
				a[i]='\0';
			}
			else
			{
				ind[val]=true;
				if(i!=0){
					currIndex++;
					a[currIndex]=a[i];
					if(currIndex!=i)
						a[i]='\0';
				}	
			}
		}
		System.out.print(a);
	}

- SATHISH June 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

boolean  isAvailable(char c , char [] a ){
		for (char temp : a)
		{
			if (temp == c)
				return true;

		}
		return false;

}

- Anonymous May 23, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public void findUnique(char[] ch)
{
boolean alphabets[]=new boolean[255];
for(int i=0;i<ch.length;i++)
{
if(alphabets[j]!=true)
{
int x=ch[j];
alphabets[x]=true;
}

for(int j=0;j<alphabets.length;j++)
{
if(alphabets[j]==true)
System.out.print((char)alphabets[j]+" ");
}

}


}

- Mr. X September 05, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class FindingUniqueVakuesInArray
{
public void findUnique(char[]ch )
{
boolean alphabets[]=new boolean[255];
for(int i=0;i<ch.length;i++)
{
if(alphabets[i]!=true)
{
int x = ch[i];
alphabets[x]=true;
}
}

for(int j=0;j<alphabets.length;j++)
{
if(alphabets[j]==true)
{
System.out.print((char)j+" ");
}
}
}

- Mr. X September 05, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class FindingUniqueVakuesInArray 
{
	public void findUnique(char[]ch )
	{
	  boolean alphabets[]=new boolean[255];
	  for(int i=0;i<ch.length;i++)
	  {
		  if(alphabets[i]!=true)
		  {
			  int x = ch[i];
			  alphabets[x]=true;
		  }
	  }
	  
	  for(int j=0;j<alphabets.length;j++)
	  {
		  if(alphabets[j]==true)
		  {
			  System.out.print((char)j+" "); 
		  }
	  }
	}

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

void f2( vector<char>& v ) {
int widx=0;
int arr[26]={0};

for( int i=0, len=v.size(); i < len; ++i) {
if (arr[ v[i]-'a' ] == 0) {
v[widx++] = v[i];
++arr[ v[i]-'a' ];
}
}
for( int i = widx; i < v.size(); ++i)
v[i] = ' ';
for( const auto&a: v)
cout<<a<<" : ";
cout<<endl;

}

- Anonymous February 20, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void f2( vector<char>& v ) {
    int widx=0;
    int arr[26]={0};

    for( int i=0, len=v.size(); i < len; ++i) {
        if (arr[ v[i]-'a' ] == 0) {
            v[widx++] = v[i];
            ++arr[ v[i]-'a' ];
        }
    }
    for( int i = widx; i < v.size(); ++i)
            v[i] = ' ';
    for( const auto&a: v)
            cout<<a<<" : ";
    cout<<endl;

}

- Anonymous February 20, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void f2( vector<char>& v ) {
    int widx=0;
    int arr[26]={0};

    for( int i=0, len=v.size(); i < len; ++i) {
        if (arr[ v[i]-'a' ] == 0) {
            v[widx++] = v[i];
            ++arr[ v[i]-'a' ];
        }
    }
    for( int i = widx; i < v.size(); ++i)
            v[i] = ' ';
    for( const auto&a: v)
            cout<<a<<" : ";
    cout<<endl;

}

- lala February 20, 2019 | 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