JP Morgan Interview Question for Software Engineers


Country: India




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

This question is not clear:
What is the input ?
Give an example and expected result

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

If the input is a single string of numbers (ex '104875'), and the output should be '10*4*87-5', then here is my shot in JavaScript:

function insertStarsDashes(str) {
  let i = 0
  while(i < str.length) {
    const current = str[i]
    const next = str[i + 1]
    // Check if current and next numbers are both even
    if (current % 2 === 0 && next % 2 === 0) {
      // Slice the string into two halves, insert the star
      str = str.slice(0, i+1) + '*' + str.slice(i+1, str.length)
    // If not, check if they are both odd and insert a dash
    } else if (current % 2 === 1 && next % 2 === 1) {
      str = str.slice(0, i+1) + '-' + str.slice(i+1, str.length)
    }
    i++
  }

  return str
}

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

In Java we can write something like below:

public class InsertStarBetweenEvenAndDashBetweenOdd {

	public static void main(String[] args) 
	{
		long l=104875l;
		
		String s= ""+l;
		StringBuilder s2= new StringBuilder("");
		s2.append(s.charAt(0));
		
		for(int i=1;i<s.length();i++)
		{
			int t1= Integer.parseInt(s.charAt(i-1)+"");
			int t2= Integer.parseInt(s.charAt(i)+"");
			s2.append((t1%2==0?(t2%2==0?"*"+s.charAt(i):s.charAt(i)):(t2%2!=0?"-"+s.charAt(i):s.charAt(i)))+"");
			
		}
		System.out.println(s2.toString());

	}

}

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

(ex '104875'), and the output should be '10*4*87-5'

How do you predict the starting number as 10, instead why cant it be 1 and 0.

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

public class InsertcCharBetweenOddAndEven {
	public static void main(String[] args) throws IOException {
	InputStreamReader reader = new InputStreamReader(System.in);
	BufferedReader bfReader = new BufferedReader(reader);
	String line = bfReader.readLine();
	StringBuilder sb = new StringBuilder();
	sb.append(line.charAt(0));
	for(int i=1;i<line.length();i++){
		if(line.charAt(i)%2==0 && line.charAt(i-1)%2==0) {
			sb.append("*"+line.charAt(i));
		}else if(line.charAt(i)%2!=0 && line.charAt(i-1)%2!=0) {
			sb.append("-"+line.charAt(i));
		}
		else {
			sb.append(line.charAt(i));
		}
	}
	System.out.println(sb.toString());
	}
}

- amit December 03, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def insert_bewteen(number):
	strrrr = []
	for i in range(0, len(number) - 1):
		is_last = i == len(number) - 2
		if int(number[i]) % 2 == 0 and int(number[i + 1]) % 2 == 0:
			strrrr.append(number[i] + "*")
		elif int(number[i]) % 2 == 1 and int(number[i + 1]) % 2 == 1:
			strrrr.append(number[i] + "-")
		else:
			strrrr.append(number[i])
		if is_last:
			strrrr.append(number[i + 1]) #gdamn
	print "".join(strrrr)

- ewarrenG January 17, 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