Autocoder

BNY coding round questions with solutions

Last updated 2026-11-19

BNY technology assessments are commonly described as coding problems at easy to medium level with some technical MCQs. Hash-based comparisons, linked lists, trees, monotonic stacks and SQL are good practice for that level. The ten problems below follow that style, including a ledger-reconciliation exercise that reflects the kind of data matching financial services do. None is a recalled question.

Each answer has the approach, complexity, the common mistake and runnable Python and Java. For interviews, see BNY interview questions.

StyleEasy to medium hashing, lists, trees, stacks, SQL, MCQs
Languages herePython, Java, SQL
Problems8 coding, 1 SQL, 2 MCQ
LevelEasy to hard

How to approach this set

Linked-list problems are easiest to get right by drawing the pointers before and after each step. For each, run your code by hand on lists of length zero, one and two, since that is where off-by-one errors hide.

The reconciliation problem is about being explicit with edge cases: duplicates, missing keys and exact money arithmetic. See how to crack an online assessment and how to crack a technical MCQ test for the objective parts.

BNY coding round questions with solutions: questions with worked answers

  1. 1

    Reconcile two ledgers: given two lists of (transaction id, amount), report ids missing from either list and ids whose amounts differ.

    medium

    Load each list into a hash map from id to amount. Ids in A but not in B are missing from B, ids in B but not in A are missing from A, and ids in both with different amounts are mismatches. Time O(n + m), space O(n + m). With money, compare exact decimals or integer minor units, never floating-point equality. Duplicated ids within one list need a rule: sum them, flag them or reject them; state the choice.

    python
    def reconcile(a, b):
        da, db = dict(a), dict(b)
        missing_in_b = sorted(set(da) - set(db))
        missing_in_a = sorted(set(db) - set(da))
        mismatched = sorted(k for k in da.keys() & db.keys() if da[k] != db[k])
        return missing_in_b, missing_in_a, mismatched
    java
    import java.util.*;
    class Solution {
        static List<List<String>> reconcile(Map<String, Long> a, Map<String, Long> b) {
            List<String> missingInB = new ArrayList<>(), missingInA = new ArrayList<>(), mismatched = new ArrayList<>();
            for (String k : a.keySet()) {
                if (!b.containsKey(k)) missingInB.add(k);
                else if (!a.get(k).equals(b.get(k))) mismatched.add(k);
            }
            for (String k : b.keySet()) if (!a.containsKey(k)) missingInA.add(k);
            Collections.sort(missingInB); Collections.sort(missingInA); Collections.sort(mismatched);
            return List.of(missingInB, missingInA, mismatched);
        }
    }
  2. 2

    Check whether a singly linked list is a palindrome in O(n) time and O(1) space.

    medium

    Find the middle with slow and fast pointers, reverse the second half in place, compare it with the first half node by node, and optionally restore the list. Time O(n), space O(1). Copying values into an array and comparing is simpler but uses O(n) space. Mistake: forgetting that for odd lengths the middle node needs no match, which the comparison loop handles by stopping when the reversed half ends.

    python
    def is_palindrome(head):
        slow = fast = head
        while fast and fast.next:
            slow, fast = slow.next, fast.next.next
        prev = None
        while slow:
            slow.next, prev, slow = prev, slow, slow.next
        left, right = head, prev
        while right:
            if left.val != right.val:
                return False
            left, right = left.next, right.next
        return True
    java
    class Solution {
        static class ListNode { int val; ListNode next; }
        static boolean isPalindrome(ListNode head) {
            ListNode slow = head, fast = head;
            while (fast != null && fast.next != null) { slow = slow.next; fast = fast.next.next; }
            ListNode prev = null;
            while (slow != null) { ListNode nx = slow.next; slow.next = prev; prev = slow; slow = nx; }
            ListNode l = head, r = prev;
            while (r != null) {
                if (l.val != r.val) return false;
                l = l.next; r = r.next;
            }
            return true;
        }
    }
  3. 3

    Two sum in a sorted array: return the 1-based indices of two numbers that add up to a target.

    easy

    Place pointers at both ends. If the sum is too small, move the left pointer right; if too large, move the right pointer left; when it matches, return the indices. Time O(n), space O(1), using the sorted order. A hash map also works but wastes the sortedness. Mistake: using binary search for each element without noticing that two pointers is simpler and linear.

    python
    def two_sum_sorted(a, target):
        l, r = 0, len(a) - 1
        while l < r:
            s = a[l] + a[r]
            if s == target:
                return [l + 1, r + 1]
            if s < target:
                l += 1
            else:
                r -= 1
        return []
    java
    class Solution {
        static int[] twoSumSorted(int[] a, int target) {
            int l = 0, r = a.length - 1;
            while (l < r) {
                int s = a[l] + a[r];
                if (s == target) return new int[]{l + 1, r + 1};
                if (s < target) l++; else r--;
            }
            return new int[0];
        }
    }
  4. 4

    Symmetric tree: is a binary tree a mirror image of itself?

    easy

    Compare the left and right subtrees as mirrors: two nodes mirror each other if their values are equal, the left child of one mirrors the right child of the other, and the right child of one mirrors the left of the other. Two nulls mirror; one null does not. Time O(n), space O(h). Mistake: comparing left with left and right with right, which checks equality of subtrees, not symmetry.

    python
    def is_symmetric(root):
        def mirror(a, b):
            if a is None and b is None:
                return True
            if a is None or b is None or a.val != b.val:
                return False
            return mirror(a.left, b.right) and mirror(a.right, b.left)
        return root is None or mirror(root.left, root.right)
    java
    class Solution {
        static class TreeNode { int val; TreeNode left, right; }
        static boolean isSymmetric(TreeNode root) {
            return root == null || mirror(root.left, root.right);
        }
        static boolean mirror(TreeNode a, TreeNode b) {
            if (a == null && b == null) return true;
            if (a == null || b == null || a.val != b.val) return false;
            return mirror(a.left, b.right) && mirror(a.right, b.left);
        }
    }
  5. 5

    Merge two sorted linked lists into one sorted list.

    easy

    Use a dummy head and a tail pointer. At each step attach the smaller of the two current nodes to the tail and advance that list. When one list is exhausted, attach the other. Time O(m + n), space O(1) since nodes are reused. Mistake: forgetting the dummy node, which turns the empty-list cases into special code, and using strict less-than so equal values from the second list are placed first (breaks stability).

    python
    class ListNode:
        def __init__(self, val=0, next=None):
            self.val, self.next = val, next
    
    def merge_two(a, b):
        dummy = tail = ListNode()
        while a and b:
            if a.val <= b.val:
                tail.next, a = a, a.next
            else:
                tail.next, b = b, b.next
            tail = tail.next
        tail.next = a or b
        return dummy.next
    java
    class Solution {
        static class ListNode { int val; ListNode next; ListNode(int v) { val = v; } }
        static ListNode mergeTwo(ListNode a, ListNode b) {
            ListNode dummy = new ListNode(0), tail = dummy;
            while (a != null && b != null) {
                if (a.val <= b.val) { tail.next = a; a = a.next; }
                else { tail.next = b; b = b.next; }
                tail = tail.next;
            }
            tail.next = (a != null) ? a : b;
            return dummy.next;
        }
    }
  6. 6

    Stock span: for each day, the number of consecutive previous days (including today) with a price less than or equal to today's.

    medium

    Keep a stack of (price, span) with decreasing prices. For a new price, pop entries with price at most the new one, adding their spans to today's span, then push (price, span). Each entry is pushed and popped at most once, so a stream of n prices costs O(n) overall (amortised O(1) each) and O(n) space. The naive scan back is O(n^2). Mistake: using strict less-than when the problem says less than or equal.

    python
    def stock_spans(prices):
        st, out = [], []
        for p in prices:
            span = 1
            while st and st[-1][0] <= p:
                span += st.pop()[1]
            st.append((p, span))
            out.append(span)
        return out
    java
    import java.util.*;
    class Solution {
        static int[] stockSpans(int[] prices) {
            Deque<int[]> st = new ArrayDeque<>();
            int[] out = new int[prices.length];
            for (int i = 0; i < prices.length; i++) {
                int span = 1;
                while (!st.isEmpty() && st.peek()[0] <= prices[i]) span += st.pop()[1];
                st.push(new int[]{prices[i], span});
                out[i] = span;
            }
            return out;
        }
    }
  7. 7

    Maximum profit from a stock with unlimited buy and sell transactions (you hold at most one share).

    easy

    Greedy: every rise between consecutive days can be captured, so add price[i] minus price[i-1] whenever it is positive. This equals buying at each valley and selling at each peak. Time O(n), space O(1). Mistake: confusing this with the single-transaction version that tracks a minimum price, or searching for peaks and valleys explicitly, which is more code for the same answer.

    python
    def max_profit(p):
        return sum(max(0, p[i] - p[i - 1]) for i in range(1, len(p)))
    java
    class Solution {
        static int maxProfit(int[] p) {
            int total = 0;
            for (int i = 1; i < p.length; i++) total += Math.max(0, p[i] - p[i - 1]);
            return total;
        }
    }
  8. 8

    SQL: list accounts whose running balance ever went below zero, with the first date it did.

    hard

    Compute the running balance per account with a window SUM ordered by date and id, filter rows where the balance is negative, and take the minimum date per account. The ORDER BY must include a tie-breaker, otherwise two same-day transactions can show an arbitrary order and a transient negative balance. Group in the outer query to get one row per account.

    sql
    SELECT account_id, MIN(txn_date) AS first_negative_date
    FROM (
      SELECT account_id, txn_date,
             SUM(amount) OVER (PARTITION BY account_id ORDER BY txn_date, txn_id) AS balance
      FROM Transactions
    ) t
    WHERE balance < 0
    GROUP BY account_id;
  9. 9

    Java MCQ: what does the final keyword mean on a variable, a method and a class?

    easy

    A final variable can be assigned only once (for a reference, the reference cannot change, but the object it points to can still be mutated). A final method cannot be overridden. A final class cannot be extended, as with String. final is not the same as immutable, and it is also not the same as the finally block or the finalize method. For fields, final also gives safe publication guarantees across threads once the constructor finishes.

  10. 10

    Spring MCQ: what is the default scope of a Spring bean, and what is the consequence?

    medium

    Singleton: the container creates one instance per application context and shares it everywhere. The consequence is that singleton beans must be thread-safe and should not hold per-request mutable state. For per-request or per-session state, use the request or session scope, or pass state through method parameters. Prototype scope creates a new instance on every request for the bean, but injecting a prototype into a singleton still gives the singleton one instance unless you use a provider or lookup method.

Frequently asked questions

How hard is the BNY coding test?

It is commonly described as easy to medium. Strong fundamentals and careful edge-case handling matter most.

Does it include SQL?

Technology roles are sometimes reported to include SQL. Practise window functions and gap detection.

Are Java and Spring MCQs common?

For Java roles, technical MCQs on Java and Spring are commonly reported. Prepare the basics such as bean scopes and the final keyword.

Are these the real questions?

No. They are original practice problems in the style of the topics the round commonly covers.

Related guides

More in Company Interview Questions

See all in this section