As reported: Morgan Stanley Technology Apprenticeship Program (SDE intern, 2027 batch) OA on AMCAT / SHL (Apr 2026, about 111 minutes): debugging (15 min, 7 small snippets with 1–2 bugs each), aptitude (36 min, 24 interactive questions) and coding (60 min, 3 LeetCode-medium-level questions). Coding question 2, a variant of LeetCode 740 (Delete and Earn): from an array such as
[8,3,4,2,2,7], repeatedly pick an elementx, addxto the score, and removextogether with every occurrence ofx−1andx+1, until the array is empty; return the score.
Practise it as LeetCode 740 — Delete and Earn:
You are given an integer array nums. Repeat the following until nums is empty: pick any nums[i], earn nums[i] points, then delete it and every element equal to nums[i] − 1 or nums[i] + 1. Return the maximum number of points you can earn.
Example 1
nums = [8,3,4,2,2,7] -> 16 take 2, 2, 4 and 8 (3 and 7 are deleted along the way)
Example 2
nums = [2,2,3,3,3,4] -> 9 take the three 3s; the 2s and the 4 are deleted
Constraints: 1 ≤ nums.length ≤ 2 · 10^4; 1 ≤ nums[i] ≤ 10^4.
Code runner format: one JSON value per line: nums (LeetCode's test-case format). Implement deleteAndEarn(nums); the harness prints the maximum score.