← J.P. Morgan Interview Insights

J.P. Morgan·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Had a technical screen for a Data Scientist role at J.P. Morgan that turned into more of an algorithms session than I expected. The main focus was implementing square root from scratch, which sounds straightforward until you're actually doing it under pressure with someone watching.

Questions Asked (1)

Q1

Implement a function that returns the integer part of the square root of a non-negative integer, without using any built-in sqrt or exponent operator. Handle large 32-bit integers without overflow. Then discuss time and space complexity.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I went straight to binary search, which felt right.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints and edge cases, then propose an efficient algorithm like binary search on the range [0, x] to find the integer square root. Emphasize overflow-safe arithmetic (e.g., using division instead of multiplication) and analyze time and space complexity.

Pro tip: Mention that binary search is preferred over Newton's method for its simplicity and guaranteed O(log n) time, but note that Newton's method can be faster in practice with careful implementation. Also, highlight the importance of testing with large 32-bit integers like 2^31-1 to ensure no overflow.

1. Clarify requirements and edge cases

Confirm the input range (non-negative 32-bit integer) and expected output (integer part of square root). Discuss edge cases: 0, 1, and maximum 32-bit integer.

2. Choose an algorithm

Select binary search over the range [0, x] to find the largest integer whose square is ≤ x. Alternatively, mention Newton's method but note potential pitfalls.

3. Implement with overflow safety

Write code that avoids overflow by using division (mid <= x / mid) instead of multiplication (mid * mid <= x). Handle the case when x is 0 separately.

4. Analyze complexity

State that time complexity is O(log x) due to binary search, and space complexity is O(1) as only a few variables are used.

5. Test and validate

Walk through test cases: x=0, x=1, x=4, x=8, x=2^31-1. Verify correctness and absence of overflow.

Key Points to Mention

  • Binary search on the answer space [0, x] with O(log x) time.
  • Overflow-safe comparison using division: mid <= x / mid.
  • Edge cases: x=0, x=1, and maximum 32-bit integer (2^31-1).
  • Space complexity O(1) with iterative implementation.
  • Alternative approaches: Newton's method (faster convergence but more complex) and bit manipulation.
  • Importance of not using built-in sqrt or exponent operator.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.