JP Morgan Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

// ZoomBA
s = "test"  
l = s.value 
r = [0:#|l|]
permutations = set()
join( @ARGS = list(r) as { l } ) where {
    continue ( #|set($.o)| != #|l| ) // mismatch and ignore 
    v = str($.o,'') as { l[$.o] }
    continue ( v @ permutations ) // if it already occurred 
    permutations += v // add them there  
    false // do not add  
}
println( permutations )

- NoOne October 07, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

O(n!) time complexity.

- zr.roman March 03, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class PossibleCombinations {
public static void main(String[] arr) {
combination("", "1234");
}

private static void combination(String prefix, String str) {
int n = str.length();
if (n == 0)
System.out.println(prefix);
else {
for (int i = 0; i < n; i++)
combination(prefix + str.charAt(i), str.substring(0, i) + str.substring(i + 1, n));
}
}

}

- shin.subash March 11, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here is python solution:

def next_permutation(data):
    size = len(data)
    for i in reversed(range(size - 1)):
        if data[i] < data[i+1]:
            data[i+1:size] = reversed(data[i+1:size])
            for j in range(i + 1, size):
                if(data[i] < data[j]):
                    data[i], data[j] = data[j], data[i]
                    return True
    return False	

def all_permutation(inp):
    ls = list(inp)
    while True:
        print ''.join(ls)
        if not next_permutation(ls):
            break
all_permutation('test')

- shamshad.npti March 29, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can solve the problem in recursive way, but it is dynamic programming so that we won't solve the same problem again and again.
e.g. consider string "abcd". We will make "ab" as prefix and try combination of "cd". Then we will make "ba" as prefix and try combination of "cd". So we are trying combinations of "cd" twice.
So as soon as we complete finding combination of sub-string it should be stored and reused.

- Kaushik Lele April 15, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Recursive solution in Swift with saving the string built so far :

var arr = Array("ABC".characters)
var permutations = [String]()

func computePerm(arr: [Character], prefix: String) {
    if arr.count == 0 {
        permutations.append(prefix)
    } else {
        var newPrefix = prefix
        for i in (0..<arr.count) {
            var newArr = arr
            newArr.removeAtIndex(i)
            computePerm(newArr, prefix: prefix + String(arr[i]))
        }
    }
}

computePerm(arr, prefix: "")
print(permutations)

- aquio July 19, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void permutate(String s) {
		if(s == null || s.length() == 0) {
			return;
		}
		permutate(s.toCharArray(), 0);
	}
	private static void permutate(char[] str, int start) {
		if(start >= str.length) {
			System.out.println(new String(str));
			return;
		}
		for(int i = start; i < str.length; i++) {
			swap(str, i, start);
			permutate(str, start+1);
			swap(str, i, start);
		}
	}
	private static void swap(char[] input, int i, int j) {
		char c = input[i];
		input[i] = input[j];
		input[j] = c;

}

- mehdijazayeri3000 August 05, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

//C++ Code
#include<bits/stdc++.h>
using namespace std;

int main()
{
set<string> a;
string s;
cin>>s;
sort(s.begin(), s.end());
a.insert(s); //insert 1st element
while(next_permutation(s.begin(), s.end()))
{
a.insert(s);
}
for(auto x:a)
{
cout<<x<<endl;
}
return 0;
}

- Shivam Mittal August 08, 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