9 real Virtu Financial interview questions with full model answers — Coding. Drawn from the same verified bank ChannelPulse drills from (9 Virtu Financial questions in total).
9 Virtu Financial questions in the bank
1 categories covered
1 roles: Software Engineer
CodingEasyVirtu FinancialSoftware Engineer
1. Array Transformation (LeetCode)
Model answer
The task
Repeatedly adjust interior array values: lower a value that is greater than both neighbors, or raise one that is less than both. Apply each round’s changes simultaneously and stop when a round makes no changes.
Key idea
Use the array from the start of each round to decide all updates. This avoids letting an early update affect another decision in the same round.
Approach
Copy the current array to hold the next round’s values.
Check each interior element against its two neighbors in the current array.
Update the copy by one when the element is a strict local maximum or minimum.
If nothing changed, return the current array; otherwise, repeat with the copy.
from typing import List
class Solution:
def transformArray(self, arr: List[int]) -> List[int]:
while True:
next_arr = arr.copy()
changed = False
# Endpoints are never changed.
for i in range(1, len(arr) - 1):
if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:
next_arr[i] -= 1
changed = True
elif arr[i] < arr[i - 1] and arr[i] < arr[i + 1]:
next_arr[i] += 1
changed = True
if not changed:
return arr
arr = next_arr
Complexity:
Time: O(nT), where n is the array length and T is the number of rounds until stabilization.
Space: O(n) for the next-round copy.
Common follow-ups
What happens to arrays shorter than three elements? They are already stable because there are no interior elements.
Why use a copy each round? It ensures every decision uses the same previous-round state.
Can updates be made in place? Not directly; doing so can make later decisions depend on the order of iteration.
CodingEasyVirtu FinancialSoftware Engineer
2. Valid Parentheses (LeetCode)
Model answer
The task
Determine whether a string of opening and closing round, square, and curly brackets is correctly nested and matched. Return a boolean.
Key idea
A closing bracket must match the most recent unmatched opening bracket. A stack captures that order: push openings, and check each closing bracket against the stack’s top.
Approach
Return False if the string has odd length.
Map each closing bracket to its matching opening bracket.
Scan the string from left to right.
Push opening brackets onto the stack.
For a closing bracket, return False if the stack is empty or its top does not match; otherwise pop.
Return True only if the stack is empty after the scan.
class Solution:
def isValid(self, s: str) -> bool:
pairs = {")": "(", "]": "[", "}": "{"}
openings = set(pairs.values())
stack = []
for char in s:
if char in openings:
stack.append(char)
else:
# A closing bracket must match the latest unmatched opening.
if not stack or stack[-1] != pairs.get(char):
return False
stack.pop()
# Unmatched opening brackets make the sequence invalid.
return not stack
Complexity:
Time: O(n), where n is the string length; each character is processed once.
Space: O(n) in the worst case, when all characters are opening brackets.
Common follow-ups
How would you support additional bracket types? Add their matching pairs to the map.
Can you stop early? Yes; return False as soon as a closing bracket mismatches or has no opening bracket.
What if the input includes non-bracket characters? Define how to handle them, then either ignore them or reject them during the scan.
CodingEasyVirtu FinancialSoftware Engineer
3. Hexspeak (LeetCode)
Model answer
The task
Convert a decimal number to its hexadecimal representation, then express that representation using the special letter substitutions. If any hexadecimal digit cannot be represented, return "ERROR".
Key idea
Convert the number to uppercase hexadecimal. The digits 0 and 1 become O and I; digits A through F remain unchanged. Any digit from 2 through 9 makes the result invalid.
Approach
Parse the decimal string as an integer.
Format it as uppercase hexadecimal without a prefix.
Translate 0 to O and 1 to I.
Return "ERROR" if any other numeric digit appears; otherwise return the translated string.
class Solution:
def toHexspeak(self, num: str) -> str:
# Format as uppercase hexadecimal, without the "0x" prefix.
hexadecimal = format(int(num), "X")
result = []
for digit in hexadecimal:
if digit == "0":
result.append("O")
elif digit == "1":
result.append("I")
elif "A" <= digit <= "F":
result.append(digit)
else:
return "ERROR"
return "".join(result)
Complexity:
Time: O(log n), where n is the value of the input; conversion and scanning take time proportional to the number of hexadecimal digits.
Space: O(log n) for the hexadecimal representation and result.
Common follow-ups
What if lowercase hexadecimal is required? Convert the result to lowercase after translating.
How would you avoid parsing into a fixed-width integer? Use arbitrary-precision integers or perform decimal-to-hex conversion with string arithmetic.
What if the allowed symbols change? Define a digit-to-symbol mapping and reject digits absent from it.
CodingEasyVirtu FinancialSoftware Engineer
4. Is Subsequence (LeetCode)
Model answer
The task
Determine whether all characters of one string appear in another string in the same order. The characters do not need to be adjacent.
Key idea
Scan the larger string from left to right, matching the next needed character from the smaller string. If every character is matched, the smaller string is a subsequence.
Approach
Keep a pointer to the next character to match in s.
Iterate through each character in t.
Advance the pointer whenever the current character matches.
Return True once all characters in s have been matched.
If the scan ends first, return False. An empty s is automatically a subsequence.
class Solution:
def isSubsequence(self, s: str, t: str) -> bool:
matched = 0
for char in t:
if matched < len(s) and char == s[matched]:
matched += 1
if matched == len(s):
return True
return matched == len(s)
Complexity:
Time: O(len(t)) — each character in t is scanned at most once.
Space: O(1) — only a pointer is used.
Common follow-ups
What if there are many queries against the same t? Precompute each character’s positions in t, then use binary search to find the next valid position for each query character.
What if the strings are streamed? Keep the pointer into s and process each incoming character of t; stop once all characters match.
How should repeated characters be handled? Match them in order, advancing the pointer after every match; each occurrence requires a distinct position in t.
CodingEasyVirtu FinancialSoftware Engineer
5. Count Substrings with Only One Distinct Letter (LeetCode)
Model answer
The task
Count all nonempty substrings of a string whose characters are identical.
Key idea
A substring with one distinct letter must lie entirely inside a consecutive run of the same letter. A run of length k contains k * (k + 1) // 2 such substrings, so sum this value across runs.
Approach
Scan the string from left to right.
Track the length of the current consecutive run.
When the character changes, add the run’s substring count to the answer and start a new run.
Add the final run’s count after the scan.
class Solution:
def countLetters(self, s: str) -> int:
total = 0
run_length = 0
previous = None
for char in s:
if char == previous:
run_length += 1
else:
# Finish the previous run.
total += run_length * (run_length + 1) // 2
previous = char
run_length = 1
# Finish the last run.
total += run_length * (run_length + 1) // 2
return total
Complexity:
Time: O(n), for one pass through the string.
Space: O(1), using only a few counters.
Common follow-ups
Can the count be updated during the scan? Yes; add the current run length for each character, since that many valid substrings end there.
What if the string is empty? The loop and final addition both contribute zero.
What if the input is streamed? Keep the current character, run length, and accumulated total between chunks.
CodingEasyVirtu FinancialSoftware Engineer
6. How Many Apples Can You Put into the Basket (LeetCode)
Model answer
The task
Given the weights of the apples and a basket capacity of 5000, find the maximum number of apples that can fit in the basket.
Key idea
To maximize the count, consider the lightest apples first. Sorting the weights lets us greedily add apples until the next one would exceed the capacity.
Approach
Sort the weights in ascending order.
Track the total weight and the number of apples chosen.
Add each apple while the total remains within 5000.
Stop at the first apple that would exceed the capacity, and return the count.
from typing import List
class Solution:
def maxNumberOfApples(self, weight: List[int]) -> int:
capacity = 5000
total = 0
count = 0
for apple_weight in sorted(weight):
if total + apple_weight > capacity:
break
total += apple_weight
count += 1
return count
Complexity:
Time: O(n log n), due to sorting the weights.
Space: O(n), for the sorted copy.
Common follow-ups
What if the capacity is provided as an argument? Use that value instead of the fixed capacity.
What if the input must not be copied? Sort the list in place, if modifying it is allowed.
How would you handle a stream of weights? A min-heap can select the lightest weights, though maintaining the exact maximum count may require storing the weights seen so far.
CodingMediumVirtu FinancialSoftware Engineer
7. Count Number of Homogenous Substrings (LeetCode)
Model answer
The task
Count all non-empty substrings whose characters are identical. Return the count modulo \(10^9+7\).
Key idea
A consecutive run of \(k\) identical characters contains \(k(k+1)/2\) such substrings. Scan the string once, tracking the length of the current run, and add that run’s contribution when it ends.
Approach
Initialize the answer and current run length to zero.
Scan each character in order.
If it matches the previous character, extend the run; otherwise, start a new run of length one.
Add the current run length to the answer. This counts the valid substrings that end at the current position.
Return the answer modulo \(10^9+7\).
class Solution:
def countHomogenous(self, s: str) -> int:
mod = 10**9 + 7
total = 0
run_length = 0
previous = None
for char in s:
if char == previous:
run_length += 1
else:
run_length = 1
previous = char
# Each suffix of the current run is a valid substring
# ending at this position.
total = (total + run_length) % mod
return total
Complexity:
Time: O(n), for one pass over the string.
Space: O(1), using only a few variables.
Common follow-ups
Why add the run length at each position? Each position can end as many valid substrings as there are characters in its current matching run.
Can the total be computed per run instead? Yes; for each run of length \(k\), add \(k(k+1)/2\).
What if the modulus changes? Replace the constant with the required modulus; the scan is unchanged.
What if the string is streamed? Keep the current character, run length, and accumulated total, updating them as each character arrives.
CodingHardVirtu FinancialSoftware Engineer
8. Optimal Account Balancing (LeetCode)
Model answer
The task
Given transactions between people, find the smallest number of additional transfers needed to make everyone’s net balance zero. The transfer amounts can be chosen freely.
Key idea
Combine all transactions into one net balance per person, then ignore people whose balance is already zero. Recursively settle one remaining balance against an opposite-sign balance; skipping duplicate balances and stopping after an exact cancellation avoids redundant work.
Approach
Subtract each transaction amount from the sender’s balance and add it to the receiver’s.
Keep only nonzero balances.
Find the first unsettled balance and try pairing it with each distinct balance of the opposite sign.
Apply the pair’s net effect, recurse, and restore the balance.
Return the minimum number of transfers across those choices.
class Solution:
def minTransfers(self, transactions: list[list[int]]) -> int:
# A positive balance means the person is owed money.
balances = {}
for sender, receiver, amount in transactions:
balances[sender] = balances.get(sender, 0) - amount
balances[receiver] = balances.get(receiver, 0) + amount
debts = [balance for balance in balances.values() if balance != 0]
def settle(start: int) -> int:
# Skip people whose balance has already been settled.
while start < len(debts) and debts[start] == 0:
start += 1
if start == len(debts):
return 0
best = float("inf")
tried = set()
for i in range(start + 1, len(debts)):
# Only pair balances with opposite signs.
if debts[start] * debts[i] >= 0 or debts[i] in tried:
continue
tried.add(debts[i])
# Settle the first balance against this one.
debts[i] += debts[start]
best = min(best, 1 + settle(start + 1))
debts[i] -= debts[start]
# An exact cancellation is an optimal pairing for this choice.
if debts[i] + debts[start] == 0:
break
return best
return settle(0)
Complexity:
Time: O(m!), worst case, where m is the number of nonzero balances; the search explores possible pairings.
Space: O(m), for the balance list and recursion stack.
Common follow-ups
Can bitmask DP be used? Yes. For small m, subset sums can find the maximum number of zero-sum groups; the answer is m minus that count.
Why skip duplicate balances? Equal balances are interchangeable, so trying both creates equivalent branches.
What if balances already sum to zero? The recursion naturally reaches the end and returns the minimum number of transfers found.
CodingHardVirtu FinancialSoftware Engineer
9. Reaching Points (LeetCode)
Model answer
The task
Determine whether a starting pair can be transformed into a target pair by repeatedly adding one coordinate to the other.
Key idea
Reverse the process: subtract the smaller target coordinate from the larger one. Batch repeated subtractions with modulo, as in the Euclidean algorithm. When one coordinate reaches its starting value, check whether the other differs from its start by a multiple of it.
Approach
While both target coordinates are at least their starting values, check whether either coordinate has reached its starting value.
If the first coordinate is fixed, test whether the second can be reduced to its start by repeated subtraction.
Apply the symmetric check if the second coordinate is fixed.
Otherwise, reduce the larger coordinate modulo the smaller.
If either coordinate drops below its start, the target is unreachable.
class Solution:
def reachingPoints(self, sx: int, sy: int, tx: int, ty: int) -> bool:
while tx >= sx and ty >= sy:
if tx == sx:
return (ty - sy) % sx == 0
if ty == sy:
return (tx - sx) % sy == 0
if tx > ty:
tx %= ty
else:
ty %= tx
return False
Complexity:
Time: O(log(max(tx, ty))) modulo steps, as in the Euclidean algorithm.
Space: O(1), using only a fixed number of variables.
Common follow-ups
What if coordinates can be zero? Handle zero divisors explicitly; modulo-based checks assume positive coordinates.
Can you provide a forward search? It branches and may grow rapidly, so reversing with modulo is much more efficient.
Why use modulo instead of subtracting once? It batches many identical reverse steps into one operation.
Practice these out loud, don't memorise them
Reading an answer is not the same as being able to give one under pressure. ChannelPulse plays the interviewer, asks the follow-ups, and scores each answer with feedback and a model answer so you can hear the gap between what you said and what lands.