Bank of America Interview Question for Software Engineer / Developers






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

public int convertStringToInt(String num){
		int result=0;
		int zeroAscii=48;
		int nineAscii=57;
		for(char c: num.toCharArray()){
			if(c>=zeroAscii && c<=nineAscii){
				result=result*10+(c-zeroAscii);
			}else
				return -1;
		}
		return result;
	}

- gamodg November 01, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

<pre lang="c" line="1" title="CodeMonkey33935" class="run-this">#include <stdio.h>
#include <string.h>

int main()
{
char *s = "12345";
char *p;
int sum = 0;

for(p = s; *p!='\0';p++)
sum = sum*10 + ((int)*p-'0');
printf("%d\n", sum);

return 0;
}


</pre><pre title="CodeMonkey33935" input="yes">
</pre>

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

//C++ COde
int zeroAscii = 48;
int value = 0;
string str = "98989";
int len = strlen(str);
for (int i=0;str!=NULL;++str,++i)
  i += ((int)(str[0])-zeroAscii)*pow(10,len-i);

- Anonymous October 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The fastest way to get number of a given string:
int number = 98989;

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

LOL..

- Anonymous October 31, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int string_to_positive_int(char *szN)
{
int nTotal = 0;

while (*szN)
{
nTotal = *szN++ - '0' + nTotal << 1 + nTotal << 3;
}

return nTotal;
}

- Anonymous October 09, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

char* str;
int tot = 0;

for(char* i = str; i != NULL; i++)
   tot = 10*tot+i-'0';

- yuchen.m.pan February 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here is the solution...

public static void main(String args[]){
		
		String numStr = "123456";
		
//		1*100000 (10^5)= 100000
//		2*10000 (10^4) =  20000
//		3*1000 (10^3)  =   3000
//		4*100 (10^2)   =    400
//		5*10 (10^1)    =     50
//		6*1 (10^0)     =      6
//		------------------------
//		                 123456
//		------------------------
		
		int length = numStr.length();
		char[] charArr = numStr.toCharArray();
		int total = 0;
		int index=length-1;
		for(int i=0;i<length;i++){
			total = (int) (total + (charArr[index]-48)*Math.pow(10, i));
			index--;
		}
		
		System.out.println(total);
	}

- Rambrij Chauhan November 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Guys simple code O (n) complexity:-

public static int str_to_num(String str)
	{ 
	  int i =0 ; 	
	  int num = 0 ; 
	  int n = str.length()-1;
	  while(i<=n)
	  {
	   num = num*10 + ((int)str.charAt(i)- 48);
	   i++ ;
	  }
	  
	  return num ;

}

- Sonia Sharma July 21, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int chartoi(char *str)
{
int n=0;
for( ; *str; str++)
n = n*10 + (*str - 48);
return n;
}

- kbkunalb April 17, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ConvertStringToNumber{

public static int convertToNum(String numStr){
Char ch[ ] = numStr.toCharArray();
int sum = 0;
into zeroAsValue = (int) '0';
for(char c : ch){
into tempZeroAsValue = (int) c;
sum = (sum*10) + (tempZeroAsValue - zeroAsValue);
}

system.out.println("convertedValueIs===>" +sum);
retun sum;
}
public static void main(String arg[ ] ){
String convertString = "98989"

convertToNum(convertString);
}
}

- Lalit October 24, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

I had a few interviews with financial companies and they mostly ask stupid questions like this. Few of them actually ask questions on syntactical errors and code based errors and evaluate a candidate's skills. It's stupid to evaluate someone's skills on that basis. I guess thats the reason we have so many stupid financial institutions n even though they rob people of their money their software sux bawls.

- Anonymous October 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

"Elegance is not a dispensable luxury but a factor that decides between success and failure." -Edsger Dijkstra
These companies don't spend on clever programmers, they spend on marketing. An elegant product will succeed no matter what, even if it is not marketed

- Anonymous October 31, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Agreed

- chennavarri October 31, 2010 | Flag


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