Open In App

JPMorgan Chase & Co Interview Experience (On-Campus)

Last Updated : 12 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

JPMC OnCampus Drive had 3 rounds

The JPMC OnCampus Drive had 3 Rounds:

1. The Coding Round
2. Video Round

3. Code For Good Round

In the First Round(Coding Round), the test was conducted in hackerrank and consists of two question which were very easy. People who solve atleast 1 problem is selected to the next round
Here are few questions which appeared in my test as well as my friends
Problem 1: Is Possible
Consider a pair of intergers (a,b). The following operations can be performed on a,b in any order, zero or more times

* (a,b) -> (a+b,b)

*(a,b)-> (a,a+b)

Return a string that denotes whether or not (a,b) can be converted to (c,d) by performing the operation zero or more times

Solution: This Problem can be solve using Recurrsion or Dynamic Programming (Since Contrainst are very low I solved using Recurrsion)

Problem 2: Highly Profitable Months

The Stocks of a company are being surveyed to analyse the net profit of the company over a period

For an analysis parameter k, an interval of k concutive months is said to be hightly profitable if the values of the stock prices are strictly increasing for those months. Given the stock prices of the company for n months and the analysis parameter k find the number of highly profitable intervals.

Example : stockPrices=[5,3,5,7,8], K=3
Here the answer is 2

Solution: Here the simple traversal would work,

C++14
#include <stdio.h>

int countHighlyProfitableMonths(int stockPrices[], int n, int k) {
    int count = 0; // Counter for highly profitable intervals

    for (int i = 0; i <= n - k; i++) {
        int strictlyIncreasing = 1; // Flag to indicate if prices are strictly increasing

        for (int j = i + 1; j < i + k; j++) {
            if (stockPrices[j] <= stockPrices[j - 1]) {
                strictlyIncreasing = 0; // Not strictly increasing, set flag to 0
                break;
            }
        }

        if (strictlyIncreasing) {
            count++; // Increment count if prices are strictly increasing for k months
        }
    }

    return count;
}

int main() {
    int stockPrices[] = {5, 3, 5, 7, 8};
    int n = sizeof(stockPrices) / sizeof(stockPrices[0]);
    int k = 3;
    int count = countHighlyProfitableMonths(stockPrices, n, k);
    printf("Number of highly profitable intervals: %d\n", count);
    return 0;
}

Problem 3: Break a Palindrome

A palindrome reads the same from left to right and right to left, e.g., “mom” is a palindrome. You are given a palindrome string that must be modified if possible. Your task is to change exactly one character in the string to another character from the range ‘a’ to ‘z’ (both inclusive) so that the string meets the following three conditions:

  1. The new string is lower alphabetically than the initial string.
  2. The new string is the lowest value string alphabetically that can be created from the original palindrome after making only one change.
  3. The new string is not a palindrome.

If there is no valid way to modify the palindrome string, return the string “IMPOSSIBLE”.

Solution: O(N) Time Complexity with single traversal

C++
#include <string>
using namespace std;

string breakPalindrome(string inp) {
    int len = inp.size();

    // Case 1: If the length is even, we can modify the first non-'a' character to 'a'.
    if (len % 2 == 0) {
        for (int i = 0; i < len; i++) {
            if (inp[i] != 'a') {
                inp[i] = 'a';
                return inp; // Return the modified string as the result.
            }
        }
    } else { // Case 2: If the length is odd, we need to make sure we don't modify the middle character to 'a'.
        for (int i = 0; i < len; i++) {
            if (inp[i] != 'a' && i != len / 2) {
                inp[i] = 'a';
                return inp; // Return the modified string as the result.
            }
        }
    }

    // If no valid modification is found, return "IMPOSSIBLE".
    return "IMPOSSIBLE";
}

Problem 4: Minimum Total Cost of Reducing an Array to One Element

You are given an array nums of n integers. The array can be reduced by 1 element by performing a move. Each move consists of the following three steps:

  1. Pick two different elements num1 and num2 from the array.
  2. Remove the two selected elements from the array.
  3. Add the sum of the two selected elements to the end of the array.

Each move has a cost associated with it: the sum of the two elements removed from the array during the move. Your task is to calculate the minimum total cost of reducing the array to one element.

Solution: Using Min Heap we can solve (STL)

C++
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int minimumTotalCost(vector<int>& nums) {
    // Create a priority queue (min heap)
    priority_queue<int, vector<int>, greater<int>> pq(nums.begin(), nums.end());

    int totalCost = 0;

    // While there are more than one element in the priority queue
    while (pq.size() > 1) {
        // Extract the two smallest elements
        int num1 = pq.top();
        pq.pop();
        int num2 = pq.top();
        pq.pop();

        // Calculate the cost of the move and add it to totalCost
        int cost = num1 + num2;
        totalCost += cost;

        // Calculate the new element and insert it into the priority queue
        int newNum = num1 + num2;
        pq.push(newNum);
    }

    return totalCost;
}

int main() {
    vector<int> nums = {5, 3, 8, 2};
    int result = minimumTotalCost(nums);
    cout << "Minimum total cost: " << result << endl;
    return 0;
}

Problem 5: Find the Longest Even Word

You are given a string sentence, consisting of words separated by spaces. Each word is a substring consisting of English alphabetic letters only. Your task is to find the first word in the sentence that has a length which is both an even number and greater than or equal to the length of any other word of even length in the sentence. If there are multiple words meeting the criteria, return the one which occurs first in the sentence.

Solution: Easy

C++
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

// Helper function to check if a number is even
bool isEven(int n) {
    return n % 2 == 0;
}

// Function to find the first word with the longest even length
string longestEvenWord(string sentence) {
    string longestEven = ""; // Initialize variable to store the longest even word
    int maxEvenLength = 0;   // Initialize variable to store the maximum even length found so far

    // Use istringstream to separate words from the sentence
    istringstream iss(sentence);
    string word;

    while (iss >> word) {
        int wordLength = word.length();

        // Check if the current word has an even length and is longer than the previously found longest even word
        if (isEven(wordLength) && wordLength > maxEvenLength) {
            longestEven = word;       // Update longestEven with the current word
            maxEvenLength = wordLength; // Update maxEvenLength with the length of the current word
        }
    }

    return longestEven; // Return the first word with the longest even length found
}

int main() {
    string sentence1 = "Time to write great code";
    string result1 = longestEvenWord(sentence1);
    cout << "Output 1: " << result1 << endl;

    string sentence2 = "The sun sets at midnight";
    string result2 = longestEvenWord(sentence2);
    cout << "Output 2: " << result2 << endl;

    string sentence3 = "This is an example";
    string result3 = longestEvenWord(sentence3);
    cout << "Output 3: " << result3 << endl;

    return 0;
}

Problem 6: Find Missing Words as Subsequence

Given two strings s and t, s being the original string, and t being a subsequence of s, your task is to find the words missing in t (case sensitive) and return them in order.

A subsequence of a string occurs when all letters of the first string (s) occur in the same order with the second string (t). The words in the strings are space-delimited.

C++
string s = "I like cheese";
string t = "I cheese";
vector<string> result = findMissingWords(s, t);
// Output: ["like"]
// Explanation: The words in `s` are ["I", "like", "cheese"], and the words in `t` are ["I", "cheese"]. 
// The missing word in `t` is "like", and it occurs after "I" in the original `s`.

Problem 7: Binary Sorting

You are given an array of decimal integers. Rearrange the array according to the following rules:

  1. Sort the integers in ascending order of the number of ‘1’s in their binary representations.
  2. For elements having the same number of ‘1’s, sort them in ascending order of their decimal values.
C++
vector<int> nums1 = {5, 3, 7, 10};
vector<int> result1 = ascendingBinarySorting(nums1);
// Output: [3, 5, 10, 7]
// Explanation: The binary representations of [5, 3, 7, 10] are [101, 11, 111, 1010], which have 2, 2, 3, and 2 '1's respectively. 
// So, after sorting in ascending order by the number of '1's, we get [3, 5, 10, 7].
// Among elements with the same number of '1's, we sort them in ascending order of their decimal values.

vector<int> nums2 = {1, 2, 3, 4, 5};
vector<int> result2 = ascendingBinarySorting(nums2);
// Output: [1, 2, 4, 3, 5]
// Explanation: The binary representations of [1, 2, 3, 4, 5] are [1, 10, 11, 100, 101], which have 1, 1, 2, 1, and 2 '1's respectively. 
// So, after sorting in ascending order by the number of '1's, we get [1, 2, 4, 3, 5].
// Among elements with the same number of '1's, we sort them in ascending order of their decimal values.

There are many Questions On Arrays, Strings and Math based. In my experience it the qualifier rund is very easy to clear

Round 2: Video Round:

There will be Two Question asked, Both have to be answered within 2 mins and you will be given 30 sec preparation time after the question is displayed. These questions would be same for every one in your college. Mostly these questions would be like HR Questions, Not the DSA once

Round 3: CodeForGood
This year, Code for Good was conducted physically at the JPMC Campus. Participants were given real-life problem statements to work on. The winning team of Code for Good will have the opportunity to be considered for an SDE (Software Development Engineer) role, based on their performance. Additionally, other teams also have a chance of being selected if they have performed well and impressed their mentor



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads