← Visa Interview Insights

Visa·Software Engineer·Onsite - Coding / Algorithms·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Visa coding round for a Software Engineer role. One problem, LeetCode Hard territory, and I left feeling pretty beaten up about it.

Questions Asked (1)

Q1

Given a list of people, each with zero, one, or both of two specific skills and an associated cost, return an array where the value at index K represents the minimum total cost to select people such that at least K of them have both skills. Use -1 where it's not possible.

Algorithms & Data Structures
Author's notes

It's a variant of a known LeetCode problem but the twist of returning answers for every K from 1 to n in one shot is what killed me.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a min-cost selection where each person can cover one or both skills. Precompute the cheapest costs for each skill category (only skill A, only skill B, both skills), then combine them efficiently to find the minimum cost for each K. Use sorting and prefix sums or dynamic programming to compute the answers for all K.

Pro tip: Clarify the constraints upfront (e.g., number of people, cost range) to choose the right algorithm; often a greedy approach with sorted lists works after separating people by skill sets.

1. Understand the problem and constraints

Restate the problem in your own words and ask clarifying questions about input size, cost ranges, and whether people can be selected multiple times. This ensures you design an efficient solution.

2. Categorize people by skills

Separate people into three groups: those with only skill A, only skill B, and both skills. Sort each group by cost ascending.

3. Precompute prefix sums

For each group, compute prefix sums of costs so you can quickly get the total cost of selecting the cheapest i people from that group.

4. Combine groups to find minimum cost for each K

For each possible number of people with both skills (from 0 to K), determine how many from the single-skill groups are needed to cover the remaining K. Use the prefix sums to compute the total cost and take the minimum.

5. Handle impossible cases and return result

If for some K it's impossible to select enough people, set the answer to -1. Return the array of minimum costs for K from 0 to the maximum possible.

Key Points to Mention

  • Time and space complexity analysis of the proposed solution.
  • Edge cases: no people, K larger than total people, all people have only one skill, etc.
  • Why sorting and prefix sums are effective for this problem.
  • How to efficiently iterate over the number of people with both skills.
  • Potential alternative approaches (e.g., dynamic programming) and their trade-offs.
  • Handling of -1 for impossible cases.

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