← Akuna Capital Interview Insights

Akuna Capital·Software Engineer·Onsite - Coding / Algorithms·Intermediate

Intermediate
Apr 2026

Summary

Akuna Capital coding round for a software engineer role. Three algorithmic problems back to back, all C++, all with tight complexity targets. The problems were genuinely hard and covered a weird mix of topics.

Questions Asked (3)

Q1

You have an inventory array where each element is the starting sale price for that item type. Every time you sell a unit of a type, its price drops by 1 (flooring at 0). You need to make exactly a given number of sales to maximize total revenue. Return the result modulo 1e9+7. Inventory can be up to 2e5 elements, orders up to 1e13, prices up to 1e9.

Algorithms & Data Structures
Author's notes

This one wrecked me at first.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Recognize that to maximize revenue, you should always sell the item with the current highest price. Use a max-heap to simulate this process, but since orders can be up to 1e13, you must batch sales by processing groups of equal prices. For each group, compute how many sales can be made before the price drops to the next distinct level, and sum the revenue using arithmetic series formulas.

Pro tip: Mention that you can avoid simulating each sale by using a priority queue of (price, count) pairs and processing in batches, which reduces time complexity to O(n log n). Also, emphasize the importance of using modulo 1e9+7 only at the end or carefully during summation to avoid overflow.

1. Understand the problem and constraints

Clarify that each sale reduces the price of that item type by 1, and you must make exactly the given number of sales. Note the large constraints: orders up to 1e13, so O(orders) simulation is infeasible.

2. Choose the right data structure

Use a max-heap (priority queue) to always access the current highest price. To handle large orders, store prices with their frequencies or process in batches.

3. Batch process sales

While orders remain, pop the highest price group. Determine how many sales can be made before the price drops to the next highest price (or to zero). Compute the number of sales in this batch as min(orders, count * (price - next_price)).

4. Compute revenue efficiently

For each batch, calculate the sum of an arithmetic series: if selling k units at decreasing prices from p down to p - (k-1), the sum is k*(2p - k + 1)/2. Apply modulo 1e9+7 carefully.

5. Handle edge cases and return result

Ensure prices don't go below zero. If orders remain after all prices reach zero, additional sales yield zero revenue. Return the total revenue modulo 1e9+7.

Key Points to Mention

  • Greedy strategy: always sell the highest-priced item to maximize revenue.
  • Use a max-heap to efficiently retrieve the current maximum price.
  • Batch processing to handle up to 1e13 orders without simulating each sale.
  • Arithmetic series formula for summing revenue over a range of decreasing prices.
  • Modulo operation (1e9+7) to prevent integer overflow and meet problem requirements.
  • Time complexity: O(n log n) due to heap operations, which is efficient for n up to 2e5.

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 two bounds minVal and maxVal, count the number of subarrays whose minimum is exactly minVal and whose maximum is exactly maxVal. Must run in O(n) time with O(1) extra space.

Algorithms & Data Structures
Author's notes

Sliding window type problem but the exact-min-and-exact-max constraint makes it trickier than it looks.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a sliding window technique with two pointers to count subarrays where all elements are within [minVal, maxVal], then subtract counts for subarrays where all elements are within [minVal+1, maxVal] and [minVal, maxVal-1], and add back the count for [minVal+1, maxVal-1]. This inclusion-exclusion approach runs in O(n) time and O(1) space.

Pro tip: Clearly explain the inclusion-exclusion principle and how the sliding window counts subarrays with elements in a given range; this demonstrates strong problem-solving skills and attention to edge cases.

1. Define helper function

Create a function countSubarraysWithBounds(low, high) that counts subarrays where every element is between low and high inclusive, using a sliding window.

2. Implement sliding window

Iterate through the array, maintaining a window [left, right] where all elements are within [low, high]. For each right, move left past any element outside the range, then add (right - left + 1) to the count.

3. Apply inclusion-exclusion

Compute total = countSubarraysWithBounds(minVal, maxVal) - countSubarraysWithBounds(minVal+1, maxVal) - countSubarraysWithBounds(minVal, maxVal-1) + countSubarraysWithBounds(minVal+1, maxVal-1).

4. Handle edge cases

If minVal > maxVal, return 0. Also ensure the helper function handles low > high by returning 0.

5. Return result

Return the computed total as the final answer.

Key Points to Mention

  • Sliding window technique for O(n) time complexity
  • Inclusion-exclusion principle to isolate subarrays with exact min and max
  • Constant space usage by only maintaining pointers and counters
  • Handling of edge cases such as minVal > maxVal or empty array
  • Time complexity analysis: each helper function runs in O(n), called four times, still O(n)
  • Space complexity: O(1) extra space

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

Q3

Given a binary matrix, two rows are considered equivalent if you can flip any subset of columns to turn one into the other. Count the number of unordered pairs of equivalent rows. Rows up to 1e5, columns up to 30. Target complexity involves bitmask or hashing tricks.

Algorithms & Data Structures
Author's notes

Probably the most interesting one.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

For each row, compute a canonical form that is invariant under column flips, such as XORing the row with its first element (or first 1) to normalize it. Then count frequencies of these canonical forms and sum C(freq, 2) for each form to get the number of unordered pairs. This works because two rows are equivalent iff their canonical forms are identical.

Pro tip: Emphasize that the canonical form must be a complete invariant: flipping columns is equivalent to XORing the row with a fixed mask, so normalizing by the first bit (or first 1) ensures uniqueness. Also mention that using a hash map with integer keys (since columns ≤ 30, the mask fits in a 32-bit integer) gives O(N) time and avoids sorting.

1. Understand the equivalence condition

Two rows are equivalent if there exists a subset of columns to flip such that one row becomes the other. This is equivalent to saying the XOR of the two rows is either all 0s or all 1s (i.e., they are bitwise complements or identical).

2. Design a canonical representation

For each row, compute a canonical form by XORing the row with a mask derived from a fixed bit (e.g., the first bit). If the first bit is 1, XOR with all 1s; otherwise keep as is. This ensures equivalent rows map to the same integer.

3. Count frequencies of canonical forms

Use a hash map to count how many rows produce each canonical form. Since columns ≤ 30, the canonical form fits in a 32-bit integer, making hashing efficient.

4. Compute the number of pairs

For each frequency f, add f*(f-1)/2 to the total count. This counts all unordered pairs of rows that share the same canonical form, i.e., are equivalent.

5. Analyze complexity and edge cases

Time complexity is O(N * C) for computing canonical forms (or O(N) if using bit operations on integers) and O(N) for hashing, so overall O(N). Space is O(N). Handle edge cases like empty matrix, single row, or all rows identical.

Key Points to Mention

  • Equivalence relation: rows are equivalent iff they are identical or bitwise complements.
  • Canonical form: XOR with first bit (or first 1) to normalize; this is a complete invariant.
  • Use of bitmask representation: each row as an integer (since columns ≤ 30).
  • Hash map for frequency counting: O(N) time, O(N) space.
  • Combinatorial counting: sum of C(f, 2) for each frequency f.
  • Complexity analysis: O(N * C) or O(N) with bit operations, well within limits for N ≤ 1e5.

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