← IBM Interview Insights

IBM·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

IBM software engineer interview with a coding question focused on implementing 1-D convolution from scratch. Pretty straightforward once you get past the terminology, but there are a few gotchas worth knowing about.

Questions Asked (1)

Q1

Implement a valid 1-D convolution function using cross-correlation semantics. Given an input array, a kernel array, and a scalar bias, compute output values only where the kernel fully overlaps the input (no padding, stride of 1), adding the bias to each output element. Handle edge cases like an empty kernel or a kernel longer than the input, and analyze the time and space complexity of your solution.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The word 'convolution' threw me off at first because I kept thinking about the flipped-kernel version from math class.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and edge cases, then describe a straightforward sliding window approach that computes each output element as the dot product of the kernel and the corresponding input slice, plus the bias. Finally, analyze time and space complexity and discuss potential optimizations.

Pro tip: Explicitly state that you will use cross-correlation semantics (no kernel flipping) and confirm the output size formula: n - k + 1, where n is input length and k is kernel length. This shows attention to detail and prevents off-by-one errors.

1. Clarify requirements and edge cases

Restate the problem: 1-D convolution with cross-correlation, no padding, stride 1, bias added. Identify edge cases: empty kernel, kernel longer than input, empty input, and kernel length equal to input length.

2. Define the algorithm

Compute output length as max(0, n - k + 1). For each valid position i from 0 to output_length-1, compute sum(input[i+j] * kernel[j] for j in range(k)) + bias.

3. Handle edge cases

If kernel is empty or kernel length > input length, return an empty array (or appropriate error). If input is empty, return empty array. Ensure bias is added only to valid outputs.

4. Analyze complexity

Time complexity: O((n - k + 1) * k) = O(n*k) in the worst case. Space complexity: O(n - k + 1) for the output array, which is O(n) in the worst case.

5. Discuss optimizations and trade-offs

Mention that for large kernels, FFT-based convolution can reduce time to O(n log n), but it adds complexity and may not be necessary for small kernels. Also note that the naive approach is cache-friendly and simple.

Key Points to Mention

  • Cross-correlation vs. convolution: clarify that no kernel flipping is required.
  • Output size formula: n - k + 1, and handling when this is <= 0.
  • Edge cases: empty kernel, kernel longer than input, empty input.
  • Bias addition: add bias to each output element after the dot product.
  • Time complexity: O(n*k) for naive implementation; space complexity: O(n) for output.
  • Potential optimizations: FFT for large kernels, but consider trade-offs in complexity and implementation effort.

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