Top 3 J.P. Morgan Coding Interview Questions from 2025
Introduction
In this blog post, we'll share the most commonly asked coding interview questions at J.P. Morgan. If you don't have months to study for your interviews, you can use AI tools like Chatmagic to generate solutions quickly and efficiently - helping you pass the interviews and get the job offer!
Problem #1: Button with Longest Push Time
You are given a 2D array events which represents a sequence of events where a child pushes a series of buttons on a keyboard. Each events[i] = [indexi, timei] indicates that the button at index indexi was pressed at time timei. The array is sorted in increasing order of time. The time taken to press a button is the difference in time between consecutive button presses. The time for the first button is simply the time at which it was pressed. Return the index of the button that took the longest time to push. If multiple buttons have the same longest time, return the button with the smallest index. Example 1: Input: events = [[1,2],[2,5],[3,9],[1,15]] Output: 1 Explanation: Button with index 1 is pressed at time 2. Button with index 2 is pressed at time 5, so it took 5 - 2 = 3 units of time. Button with index 3 is pressed at time 9, so it took 9 - 5 = 4 units of time. Button with index 1 is pressed again at time 15, so it took 15 - 9 = 6 units of time. Example 2: Input: events = [[10,5],[1,7]] Output: 10 Explanation: Button with index 10 is pressed at time 5. Button with index 1 is pressed at time 7, so it took 7 - 5 = 2 units of time. Constraints: 1 <= events.length <= 1000 events[i] == [indexi, timei] 1 <= indexi, timei <= 105 The input is generated such that events is sorted in increasing order of timei.
Topics: Array
Problem #2: Group Anagrams
Given an array of strings strs, group the anagrams together. You can return the answer in any order. Example 1: Input: strs = ["eat","tea","tan","ate","nat","bat"] Output: [["bat"],["nat","tan"],["ate","eat","tea"]] Explanation: There is no string in strs that can be rearranged to form "bat". The strings "nat" and "tan" are anagrams as they can be rearranged to form each other. The strings "ate", "eat", and "tea" are anagrams as they can be rearranged to form each other. Example 2: Input: strs = [""] Output: [[""]] Example 3: Input: strs = ["a"] Output: [["a"]] Constraints: 1 <= strs.length <= 104 0 <= strs[i].length <= 100 strs[i] consists of lowercase English letters.
Topics: Array, Hash Table, String, Sorting
Problem #3: Maximum Product of Two Elements in an Array
Given the array of integers nums, you will choose two different indices i and j of that array. Return the maximum value of (nums[i]-1)(nums[j]-1). Example 1: Input: nums = [3,4,5,2] Output: 12 Explanation: If you choose the indices i=1 and j=2 (indexed from 0), you will get the maximum value, that is, (nums[1]-1)(nums[2]-1) = (4-1)(5-1) = 34 = 12. Example 2: Input: nums = [1,5,4,5] Output: 16 Explanation: Choosing the indices i=1 and j=3 (indexed from 0), you will get the maximum value of (5-1)*(5-1) = 16. Example 3: Input: nums = [3,7] Output: 12 Constraints: 2 <= nums.length <= 500 1 <= nums[i] <= 10^3
Topics: Array, Sorting, Heap (Priority Queue)