Skip to content

JP Morgan Coding Questions - DSA Problems & Solutions

Practice JP Morgan placement paper coding questions with detailed solutions. Access JP Morgan OA coding problems in Java, C++, Python.

This page contains JP Morgan coding questions from JP Morgan OA placement papers with detailed solutions.

JP Morgan OA Coding Section:

  • Problems: 2-3 coding problems
  • Time: 60 minutes
  • Languages: C, C++, Java, Python
Q1: Find indices of two numbers that add up to target.

Solution (Java):

public int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
int complement = target - nums[i];
if (map.containsKey(complement)) {
return new int[]{map.get(complement), i};
}
map.put(nums[i], i);
}
return new int[]{};
}

Time Complexity: O(n)


Practice JP Morgan coding questions regularly!