Check if a numeric string is divisible by 8
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Technical Screen
Quick Answer: Determine whether a very large non-negative integer given as a decimal string is divisible by 8 without converting the whole string to an integer. The key insight is that only the last three digits matter (since 1000 is a multiple of 8), giving an O(1) check; a streaming modular-remainder approach is the O(n) alternative.
Examples
Input: ('16',)
Expected Output: True
Explanation: Divisible.
Input: ('123',)
Expected Output: False
Explanation: Not divisible.
Hints
- A decimal integer is divisible by 8 iff its last three digits are divisible by 8.