← Bank of America Interview Insights

Bank of America·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Got a coding question for a Data Scientist role that felt more like a software engineering screen than anything DS-related. One question, math-flavored, and the constraint about not using built-in integer conversion is what made it actually tricky.

Questions Asked (1)

Q1

Given a very large number stored as a decimal string (potentially millions of digits long), determine whether it is divisible by 8, without converting the whole string to an integer.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

My first instinct was just int(s) % 8 == 0 and call it a day, but the constraint kills that immediately.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Explain that divisibility by 8 depends only on the last three digits of the number, so you can extract the last three characters of the string and check if that three-digit number is divisible by 8. This avoids converting the entire string to an integer, which is crucial for very large inputs.

Pro tip: Mention that this approach is O(1) time and space with respect to the number's length, and that it can be extended to other powers of 2 (e.g., divisibility by 16 uses the last four digits). This shows you understand the underlying number theory and can generalize.

1. Identify the divisibility rule

Recall that a number is divisible by 8 if and only if its last three digits form a number divisible by 8. This is because 1000 is divisible by 8.

2. Extract the last three digits

From the decimal string, take the substring of the last three characters. If the string length is less than 3, pad with leading zeros or treat the whole string as the number.

3. Convert and check divisibility

Convert the three-character substring to an integer (which is safe since it's at most 3 digits) and check if it is divisible by 8 (i.e., number % 8 == 0).

4. Handle edge cases

Consider cases where the string has leading zeros, is empty, or represents negative numbers (though the problem likely assumes non-negative). Also, if the string length is less than 3, just check the whole number.

5. Discuss complexity and alternatives

Highlight that this method is O(1) in time and space relative to the number's length, and contrast it with the naive approach of converting the entire string to an integer, which would be infeasible for millions of digits.

Key Points to Mention

  • Divisibility rule for 8: last three digits must be divisible by 8.
  • Why it works: 1000 is divisible by 8, so higher place values don't affect divisibility.
  • Time and space complexity: O(1) with respect to the number's length.
  • Edge cases: strings shorter than 3 digits, leading zeros, negative numbers.
  • Generalization to other powers of 2 (e.g., 16 uses last four digits).
  • Practical implementation: substring extraction and integer conversion of at most 3 digits.

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