Autocoder

Deutsche Bank coding round questions with solutions

Last updated 2026-11-19

Deutsche Bank technology assessments in India are commonly reported to include coding problems of medium difficulty, with dynamic programming, graphs, sorting and SQL, and objective questions on programming and CS. This set is practice in that style: eight coding problems and two MCQs. None is a recalled question.

Each answer has the approach, complexity and a common mistake, and the code is meant to run as written. For the interview rounds, see Deutsche Bank interview questions.

StyleMedium DP, graph, heap, bit and SQL problems, plus MCQs
Languages herePython, Java, SQL
Problems8 coding, 2 MCQ-style
LevelEasy to hard

How to approach this set

Graph and DP problems reward a clear state definition. Before coding, write what dp[i][j] or each heap entry means in one sentence. If you cannot, you are not ready to code yet.

Practise reading constraints for the intended complexity: n up to 10^5 rules out O(n^2). For the MCQs, eliminate options by testing a small case. More guidance is in how to crack an online assessment and DSA coding rounds.

Deutsche Bank coding round questions with solutions: questions with worked answers

  1. 1

    Length of the longest common subsequence of two strings.

    medium

    Let dp[i][j] be the LCS length of the first i characters of a and the first j of b. If the characters match, dp[i][j] = dp[i-1][j-1] + 1, otherwise the larger of dp[i-1][j] and dp[i][j-1]. Time and space O(mn); keeping only two rows reduces space to O(n). A subsequence need not be contiguous, which separates it from the longest common substring where a mismatch resets the value to 0. See dynamic programming interview questions.

    python
    def lcs(a, b):
        dp = [[0] * (len(b) + 1) for _ in range(len(a) + 1)]
        for i in range(1, len(a) + 1):
            for j in range(1, len(b) + 1):
                if a[i - 1] == b[j - 1]:
                    dp[i][j] = dp[i - 1][j - 1] + 1
                else:
                    dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
        return dp[-1][-1]
    java
    class Solution {
        static int lcs(String a, String b) {
            int[][] dp = new int[a.length() + 1][b.length() + 1];
            for (int i = 1; i <= a.length(); i++)
                for (int j = 1; j <= b.length(); j++)
                    dp[i][j] = a.charAt(i - 1) == b.charAt(j - 1)
                        ? dp[i - 1][j - 1] + 1
                        : Math.max(dp[i - 1][j], dp[i][j - 1]);
            return dp[a.length()][b.length()];
        }
    }
  2. 2

    Shortest path from a source to every node in a weighted graph with non-negative edges.

    hard

    Dijkstra's algorithm with a min-heap of (distance, node). Pop the closest unfinalised node, skip it if its stored distance is already smaller (a stale heap entry), and relax its edges. Time O((V + E) log V), space O(V + E). It fails with negative edges, where Bellman-Ford is needed. The common bug is omitting the stale-entry check, which still gives the right answer but slows it down, and forgetting that unreachable nodes keep an infinite distance.

    python
    import heapq
    def dijkstra(n, edges, src):
        g = [[] for _ in range(n)]
        for u, v, w in edges:
            g[u].append((v, w))
        dist = [float('inf')] * n
        dist[src] = 0
        h = [(0, src)]
        while h:
            d, u = heapq.heappop(h)
            if d > dist[u]:
                continue
            for v, w in g[u]:
                if d + w < dist[v]:
                    dist[v] = d + w
                    heapq.heappush(h, (dist[v], v))
        return dist
    java
    import java.util.*;
    class Solution {
        static long[] dijkstra(int n, int[][] edges, int src) {
            List<int[]>[] g = new List[n];
            for (int i = 0; i < n; i++) g[i] = new ArrayList<>();
            for (int[] e : edges) g[e[0]].add(new int[]{e[1], e[2]});
            long[] dist = new long[n];
            Arrays.fill(dist, Long.MAX_VALUE);
            dist[src] = 0;
            PriorityQueue<long[]> h = new PriorityQueue<>((a, b) -> Long.compare(a[0], b[0]));
            h.add(new long[]{0, src});
            while (!h.isEmpty()) {
                long[] cur = h.poll();
                int u = (int) cur[1];
                if (cur[0] > dist[u]) continue;
                for (int[] e : g[u]) {
                    if (cur[0] + e[1] < dist[e[0]]) {
                        dist[e[0]] = cur[0] + e[1];
                        h.add(new long[]{dist[e[0]], e[0]});
                    }
                }
            }
            return dist;
        }
    }
  3. 3

    Course schedule: given prerequisite pairs, can all courses be finished?

    medium

    This is cycle detection in a directed graph. Kahn's algorithm: compute in-degrees, start a queue with all zero in-degree nodes, remove them one at a time and reduce neighbours' in-degrees. If you process all n nodes there is no cycle. Time O(V + E), space O(V + E). Returning the processing order gives a valid study order, i.e. a topological sort. The edge direction is the usual mistake: [a, b] means b must come before a.

    python
    from collections import deque
    def can_finish(n, pre):
        g = [[] for _ in range(n)]
        indeg = [0] * n
        for a, b in pre:
            g[b].append(a)
            indeg[a] += 1
        q = deque(i for i in range(n) if indeg[i] == 0)
        done = 0
        while q:
            u = q.popleft()
            done += 1
            for v in g[u]:
                indeg[v] -= 1
                if indeg[v] == 0:
                    q.append(v)
        return done == n
    java
    import java.util.*;
    class Solution {
        static boolean canFinish(int n, int[][] pre) {
            List<Integer>[] g = new List[n];
            for (int i = 0; i < n; i++) g[i] = new ArrayList<>();
            int[] indeg = new int[n];
            for (int[] p : pre) { g[p[1]].add(p[0]); indeg[p[0]]++; }
            Deque<Integer> q = new ArrayDeque<>();
            for (int i = 0; i < n; i++) if (indeg[i] == 0) q.add(i);
            int done = 0;
            while (!q.isEmpty()) {
                int u = q.poll();
                done++;
                for (int v : g[u]) if (--indeg[v] == 0) q.add(v);
            }
            return done == n;
        }
    }
  4. 4

    Sliding window maximum: the maximum of every window of size k.

    hard

    Use a deque of indices whose values are in decreasing order. For each new index, pop smaller values from the back (they can never be the maximum while the new one is in the window), drop the front if it has left the window, and the front is the current maximum. Each index is pushed and popped once: time O(n), space O(k). A heap works in O(n log n). The mistake is storing values instead of indices, so expiry cannot be detected.

    python
    from collections import deque
    def max_window(a, k):
        dq, out = deque(), []
        for i, x in enumerate(a):
            while dq and a[dq[-1]] <= x:
                dq.pop()
            dq.append(i)
            if dq[0] <= i - k:
                dq.popleft()
            if i >= k - 1:
                out.append(a[dq[0]])
        return out
    java
    import java.util.*;
    class Solution {
        static int[] maxWindow(int[] a, int k) {
            Deque<Integer> dq = new ArrayDeque<>();
            int[] out = new int[a.length - k + 1];
            for (int i = 0; i < a.length; i++) {
                while (!dq.isEmpty() && a[dq.peekLast()] <= a[i]) dq.pollLast();
                dq.addLast(i);
                if (dq.peekFirst() <= i - k) dq.pollFirst();
                if (i >= k - 1) out[i - k + 1] = a[dq.peekFirst()];
            }
            return out;
        }
    }
  5. 5

    Count inversions in an array: pairs i < j with a[i] > a[j].

    hard

    Modify merge sort: while merging two sorted halves, whenever an element from the right half is placed before the remaining left elements, it forms an inversion with each of them, so add the number of left elements remaining. Time O(n log n), space O(n). The brute force is O(n^2). Use a 64-bit counter: n up to 10^5 can produce about 5 x 10^9 inversions, which overflows a 32-bit int.

    python
    def count_inv(a):
        def sort(x):
            if len(x) < 2:
                return x, 0
            m = len(x) // 2
            l, cl = sort(x[:m]); r, cr = sort(x[m:])
            out, i, j, c = [], 0, 0, cl + cr
            while i < len(l) and j < len(r):
                if l[i] <= r[j]:
                    out.append(l[i]); i += 1
                else:
                    out.append(r[j]); j += 1
                    c += len(l) - i
            return out + l[i:] + r[j:], c
        return sort(a)[1]
    java
    class Solution {
        static long countInv(int[] a) {
            return sort(a, new int[a.length], 0, a.length - 1);
        }
        static long sort(int[] a, int[] t, int lo, int hi) {
            if (lo >= hi) return 0;
            int mid = (lo + hi) / 2;
            long c = sort(a, t, lo, mid) + sort(a, t, mid + 1, hi);
            int i = lo, j = mid + 1, k = lo;
            while (i <= mid && j <= hi) {
                if (a[i] <= a[j]) t[k++] = a[i++];
                else { t[k++] = a[j++]; c += mid - i + 1; }
            }
            while (i <= mid) t[k++] = a[i++];
            while (j <= hi) t[k++] = a[j++];
            System.arraycopy(t, lo, a, lo, hi - lo + 1);
            return c;
        }
    }
  6. 6

    Minimum path sum from the top-left to the bottom-right of a grid, moving only right or down.

    medium

    Each cell's best cost is its own value plus the smaller of the cost from above and from the left. Fill the grid row by row; the first row and column have only one predecessor. Time O(mn), space O(n) with a single rolling row. Mistake: seeding the first row and column with the same minimum rule, which reads outside the grid.

    python
    def min_path(g):
        R, C = len(g), len(g[0])
        dp = [0] * C
        for i in range(R):
            for j in range(C):
                if i == 0 and j == 0: dp[j] = g[0][0]
                elif i == 0: dp[j] = dp[j - 1] + g[i][j]
                elif j == 0: dp[j] = dp[j] + g[i][j]
                else: dp[j] = min(dp[j], dp[j - 1]) + g[i][j]
        return dp[-1]
    java
    class Solution {
        static int minPath(int[][] g) {
            int R = g.length, C = g[0].length;
            int[] dp = new int[C];
            for (int i = 0; i < R; i++)
                for (int j = 0; j < C; j++) {
                    if (i == 0 && j == 0) dp[j] = g[0][0];
                    else if (i == 0) dp[j] = dp[j - 1] + g[i][j];
                    else if (j == 0) dp[j] += g[i][j];
                    else dp[j] = Math.min(dp[j], dp[j - 1]) + g[i][j];
                }
            return dp[C - 1];
        }
    }
  7. 7

    Every element appears twice except one. Find the single one in O(n) time and O(1) space.

    easy

    XOR all the numbers. Equal values cancel (x ^ x = 0), 0 ^ y = y, and XOR is commutative and associative, so the unpaired value remains. Time O(n), space O(1). A hash set solves it in O(n) space. If every other element appears three times, count each bit position modulo 3 instead; XOR alone does not work.

    python
    def single(a):
        r = 0
        for x in a:
            r ^= x
        return r
    java
    class Solution {
        static int single(int[] a) {
            int r = 0;
            for (int x : a) r ^= x;
            return r;
        }
    }
  8. 8

    SQL: show each transaction with the running balance per account in date order.

    medium

    A window SUM with PARTITION BY account and ORDER BY date gives the cumulative total. Add the transaction id as a tie-breaker in the ORDER BY so rows on the same date have a stable order; without it the default RANGE frame treats equal dates as peers and gives them the same running total. This pattern is a staple for finance data. See SQL window functions interview questions.

    sql
    SELECT account_id, txn_date, amount,
           SUM(amount) OVER (PARTITION BY account_id
                             ORDER BY txn_date, txn_id
                             ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS balance
    FROM Transactions;
  9. 9

    Java MCQ: what does the following print? String a = "abc"; String b = new String("abc"); System.out.println((a == b) + " " + a.equals(b));

    easy

    It prints false true. The literal a is interned in the string pool, while new String creates a distinct object on the heap, so == compares different references and is false. equals compares content and is true. Calling b.intern() would return the pooled instance and make == true. This is a favourite for assessment MCQs, along with the fact that two identical literals compare equal with ==.

  10. 10

    CS MCQ: merging k sorted lists of total n elements with a min-heap takes how long?

    medium

    O(n log k). The heap holds at most one element per list, so each push and pop costs O(log k), and each of the n elements is pushed and popped once. Merging the lists one after another would cost up to O(nk). When the options include O(n log n), note that it is correct as a bound but not the tightest.

Frequently asked questions

How hard is the Deutsche Bank coding test?

It is commonly described as medium difficulty with some harder problems, mostly arrays, strings, DP and graphs.

Does it include SQL?

Some technology roles are reported to include SQL questions. Practise joins, grouping and window functions.

Which language is allowed?

Platforms usually accept several languages including Java and Python. Check the instructions in your invitation.

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