← Visa Interview Insights

Visa·Software Engineer·Online Assessment (OA)·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Visa OA for a software engineer role, three coding problems back to back. Nothing behavioral, just pure algorithm grind. The problems ranged from pretty approachable to genuinely tricky depending on how fast you see the key insight.

Questions Asked (3)

Q1

Given two arrays `a` and `b` of the same length and an integer `k`, each index contributes `min(a[i], b[i])` to a total score. You can pick up to `k` indices and double `b[i]` at each chosen index, changing that contribution to `min(a[i], 2 * b[i])`. Return the maximum total score.

Algorithms & Data Structures
Author's notes

My first instinct was greedy and it turned out to be right, but I second-guessed myself for way too long.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start with the baseline sum of min(a[i], b[i]) for all indices, then compute the gain for each index if doubled: min(a[i], 2*b[i]) - min(a[i], b[i]). Sort gains in descending order and add the top k positive gains to the baseline. This greedy approach works because each index's gain is independent and we can choose up to k indices.

Pro tip: Mention that you only consider positive gains and that you can pick fewer than k indices if no additional positive gains exist, showing attention to edge cases and optimality.

1. Understand the problem and baseline

Compute the initial total score as the sum of min(a[i], b[i]) for all indices. This represents the score without any doubling.

2. Calculate potential gains

For each index, compute the gain if doubled: gain[i] = min(a[i], 2*b[i]) - min(a[i], b[i]). This is the increase in contribution from that index.

3. Select best indices

Sort the gains in descending order. Take the top k gains, but only if they are positive, and add them to the baseline. If fewer than k positive gains exist, take all positive gains.

4. Return the maximum total score

The sum of the baseline and the selected gains is the maximum total score. Explain why this greedy choice is optimal: gains are independent and we want the largest increases.

Key Points to Mention

  • Baseline sum computation
  • Gain calculation per index
  • Sorting gains and selecting top k
  • Handling negative or zero gains (only take positive)
  • Time complexity: O(n log n) due to sorting
  • Space complexity: O(n) for storing gains
  • Proof of greedy optimality

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

Q2

Given an integer array and a positive integer `d`, count all index triplets `(i, j, k)` with `i < j < k` such that the sum of the three elements is divisible by `d`.

Algorithms & Data Structures
Author's notes

This one stressed me out.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints (array size, value ranges) and then propose an efficient solution using remainders modulo d. Use a frequency array to count remainders and then count triplets whose remainders sum to 0 mod d, either by iterating over all remainder combinations or using a combinatorial formula.

Pro tip: Mention that the brute-force O(n^3) approach is too slow for large inputs, and that the remainder-based method reduces it to O(n + d^2), which is optimal for this problem. Also, discuss how to handle large counts using 64-bit integers to avoid overflow.

1. Clarify constraints and edge cases

Ask about the input size, value ranges, and whether d can be larger than the array length. Discuss edge cases like empty array, d=1, and negative numbers.

2. Derive the remainder-based approach

Explain that the sum of three numbers is divisible by d if and only if the sum of their remainders modulo d is divisible by d. This reduces the problem to counting triplets of remainders.

3. Count remainders and triplets

Compute the frequency of each remainder modulo d. Then count valid triplets by iterating over all combinations of three remainders (with repetition allowed) that sum to 0 mod d, using combinatorics to handle duplicates.

4. Analyze complexity and optimize

Show that the time complexity is O(n + d^2) and space O(d). Discuss potential optimizations if d is large, such as using a hash map for sparse remainders.

5. Test with examples

Walk through a small example to verify the logic, such as array [3,3,4,7,8] and d=5, and compute the count manually to ensure correctness.

Key Points to Mention

  • Modular arithmetic: sum divisible by d iff sum of remainders divisible by d.
  • Frequency array of remainders to avoid O(n^3) brute force.
  • Combinatorial counting: handle cases where remainders are equal (e.g., all three same, two same one different, all distinct).
  • Time complexity O(n + d^2) and space O(d).
  • Use 64-bit integers for counts to prevent overflow.
  • Edge cases: d=1, negative numbers (use proper modulo), and large d relative to n.

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

Q3

Given two integer arrays `A` and `B` of the same length, find the longest contiguous subarray where at each index you pick either `A[i]` or `B[i]`, and the chosen values form a non-decreasing sequence.

Algorithms & Data Structures
Author's notes

Hardest of the three for me.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem and constraints, then propose a dynamic programming solution that tracks the longest valid subarray ending at each index for both choices. Discuss time and space complexity, and consider edge cases and potential optimizations.

Pro tip: Mention that this is a variation of the longest non-decreasing subarray problem and that you can optimize space to O(1) by only keeping track of the previous state. Also, discuss how to handle ties or equal values to show attention to detail.

1. Clarify the problem

Ask clarifying questions: Are we allowed to switch between arrays arbitrarily? Is the subarray contiguous in the original arrays? What should we return if no such subarray exists? Confirm that the chosen values must be non-decreasing.

2. Define state and recurrence

Define dpA[i] as the length of the longest valid subarray ending at index i with A[i] chosen, and dpB[i] similarly for B[i]. Recurrence: dpA[i] = 1 + max(dpA[i-1] if A[i-1] <= A[i], dpB[i-1] if B[i-1] <= A[i]), and similarly for dpB[i].

3. Iterate and track maximum

Initialize dpA[0] = dpB[0] = 1. Iterate from i=1 to n-1, compute dpA[i] and dpB[i] using the recurrence, and keep track of the maximum length seen so far.

4. Analyze complexity and optimize

Time complexity is O(n) and space can be optimized to O(1) by only storing the previous dpA and dpB values. Discuss potential edge cases such as all elements equal or strictly decreasing.

5. Test with examples

Walk through a small example to verify correctness, e.g., A = [1,3,5], B = [2,2,4]. Also test edge cases like n=1, or arrays where no valid subarray longer than 1 exists.

Key Points to Mention

  • Dynamic programming with two states per index
  • Time complexity O(n) and space optimization to O(1)
  • Handling of non-decreasing condition (allow equal values)
  • Edge cases: n=1, all elements decreasing, all elements equal
  • Comparison with similar problems like longest increasing subarray
  • Potential follow-up: what if we can skip elements? (not contiguous)

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