Deutsche Bank interview prep
21 practice questions on the topics candidates reported from Deutsche Bank interviews, with answers. The questions are ours; each one links to the interview report that names its topic.
DSA 4
-
What is the running time of Dijkstra's algorithm with a binary-heap priority queue, on a graph with V vertices and E edges?
- O(V + E)
- O(V^2 log E)
- O((V + E) log V)
- O(E log E log V)
Show the answer
C. O((V + E) log V)
Every vertex is taken out of the heap once and every edge can cause one decrease-key or push, each O(log V). A plain array gives O(V^2) instead, which is better only for dense graphs.
This topic is named in a candidate’s interview report: Graduate analyst on-campus interview, 2022, on GeeksforGeeks.
-
Merge sort splits the array in half, sorts each half and merges them. What is its time complexity, and its extra space for an array?
- O(n log n) time in every case, with O(n) extra space for merging
- O(n^2) time in the worst case, with O(1) extra space
- O(n) time, with O(log n) extra space
- O(n log n) time on average but O(n^2) in the worst case
Show the answer
A. O(n log n) time in every case, with O(n) extra space for merging
There are log n levels of halving and each level merges n elements, whatever the input order. Merging needs a temporary array. Quick sort is the one that degrades to O(n^2).
This topic is named in a candidate’s interview report: Graduate analyst on-campus interview, 2023, on GeeksforGeeks.
-
What makes a recursive function tail-recursive?
- It calls itself exactly once
- The recursive call is the very last thing it does, with no work left to do after the call returns
- It recurses on the last element of a list
- It has no base case
Show the answer
B. The recursive call is the very last thing it does, with no work left to do after the call returns
fact(n) = n * fact(n - 1) is not tail-recursive: the multiplication waits for the call. With an accumulator, fact(n, acc) returns fact(n - 1, n * acc), which is. Such a call can reuse the current stack frame, turning the recursion into a loop; C and C++ compilers usually do this when optimising, while Java and Python do not.
This topic is named in a candidate’s interview report: Graduate analyst on-campus interview, 2020, on GeeksforGeeks.
-
Trains arrive at 9:00, 9:40, 9:50, 11:00, 15:00 and 18:00 and leave at 9:10, 12:00, 11:20, 11:30, 19:00 and 20:00 (the i-th arrival with the i-th departure). What is the fewest platforms needed so no train waits?
- 4
- 2
- 6
- 3
Show the answer
D. 3
Sort arrivals and departures separately and sweep through time, adding 1 at each arrival and subtracting 1 at each departure. At 11:00 the trains of 9:40, 9:50 and 11:00 are all in, which is the peak: 3. Sorting makes it O(n log n).
This topic is named in a candidate’s interview report: Graduate analyst on-campus interview, 2023, on GeeksforGeeks.
C and C++ 3
-
In C++, what is the difference between a struct and a class?
- A struct cannot have member functions
- A struct is always on the stack and a class on the heap
- Members and base classes are public by default in a struct and private by default in a class
- A struct cannot be inherited from
Show the answer
C. Members and base classes are public by default in a struct and private by default in a class
That default is the only rule that differs: both can have constructors, virtual functions, inheritance and templates. By convention, struct is used for plain bundles of data and class for types that guard their own invariants.
This topic is named in a candidate’s interview report: Graduate analyst on-campus interview, 2022, on GeeksforGeeks.
-
What does this print?
#include <stdio.h> int main(void) { int a[] = {10, 20, 30}; int *p = a; int x = ++*p; int y = *p++; printf("%d %d %d\n", x, y, *p); return 0; }- 11 10 20
- 11 11 20
- 10 11 30
- 11 11 30
Show the answer
B. 11 11 20
++*p increments what p points to, so a[0] becomes 11 and x is 11. *p++ reads *p (11) and then moves p to a[1]: postfix ++ binds tighter than *, but the old address is used for the read. So y is 11 and *p is now 20.
This topic is named in a candidate’s interview report: Graduate analyst on-campus interview, 2020, on GeeksforGeeks.
-
Can a struct in C contain functions?
- No; it can hold pointers to functions, which can be called through the struct, but not member functions
- Yes, exactly as a C++ class can
- Only static functions
- Only when compiled as C99 or later
Show the answer
A. No; it can hold pointers to functions, which can be called through the struct, but not member functions
A C struct holds data only. A field such as int (*compare)(const void *, const void *) stores a function's address, and s.compare(a, b) calls it, which is how C code imitates methods and interfaces. C has no this pointer, so the struct is usually passed in by hand.
This topic is named in a candidate’s interview report: Graduate analyst on-campus interview, 2022, on GeeksforGeeks.
OOP 4
-
Which kind of inheritance does Java not allow between classes?
- Single inheritance
- Hierarchical inheritance
- Multilevel inheritance
- Multiple inheritance: a class can extend only one class, though it can implement many interfaces
Show the answer
D. Multiple inheritance: a class can extend only one class, though it can implement many interfaces
Extending two classes would raise the diamond problem: which parent's fields and method win. Java allows one superclass and any number of interfaces; since Java 8, a clash between two default methods must be resolved in the class.
This topic is named in a candidate’s interview report: Graduate analyst on-campus interview, 2023, on GeeksforGeeks.
-
Classes B and C both inherit from A, and D inherits from both B and C. What is the diamond problem, and how does C++ deal with it?
- D cannot be written in any language
- C++ quietly uses B's copy of A
- D inherits nothing from A
- D would hold two copies of A, so using A's members through D is ambiguous; C++ solves it with virtual inheritance (class B : virtual public A), which shares one A
Show the answer
D. D would hold two copies of A, so using A's members through D is ambiguous; C++ solves it with virtual inheritance (class B : virtual public A), which shares one A
Without virtual inheritance, D has an A inside B and another inside C, and d.x does not compile. Java avoids the problem by allowing only one superclass; when two interfaces give the same default method, the class must override it and choose.
This topic is named in a candidate’s interview report: Graduate analyst on-campus interview, 2023, on GeeksforGeeks.
-
Car and Truck both need start(), stop() and fuelLevel(). What does making both extend a Vehicle class give you?
- One shared copy of that code, and the ability to treat any Car or Truck as a Vehicle, for example in a List<Vehicle>
- Faster code at run time
- Vehicle's private fields become public
- Nothing beyond renaming the classes
Show the answer
A. One shared copy of that code, and the ability to treat any Car or Truck as a Vehicle, for example in a List<Vehicle>
Inheritance gives reuse and an is-a relationship: code written for Vehicle works for every kind of vehicle. Use it when the subclass truly is a kind of the parent; when a class only needs another's behaviour, holding it as a field (composition) is usually better.
This topic is named in a candidate’s interview report: Graduate analyst on-campus interview, 2022, on GeeksforGeeks.
-
Which lazily created Java singleton is thread-safe without taking a lock on every call?
- if (inst == null) inst = new Logger(); return inst; inside a static get()
- A public constructor that callers agree to call only once
- A holder class: private static class Holder { static final Logger I = new Logger(); } and get() returns Holder.I
- A static field that every constructor call overwrites
Show the answer
C. A holder class: private static class Holder { static final Logger I = new Logger(); } and get() returns Holder.I
The JVM initialises Holder only when get() first touches it, and class initialisation is thread-safe, so the Logger is made once, lazily, with no lock afterwards. The plain null check can build two objects when two threads pass the check together. An enum with one constant is the other safe choice.
This topic is named in a candidate’s interview report: Graduate analyst on-campus interview, 2022, on GeeksforGeeks.
DBMS and SQL 10
-
How many clustered indexes can a table have?
- None
- One
- One per column
- Unlimited
Show the answer
B. One
A clustered index decides the physical order in which the rows are stored, and rows can only be stored in one order.
This topic is named in a candidate’s interview report: Graduate analyst on-campus interview, 2022, on GeeksforGeeks.
-
How does a UNIQUE constraint differ from a PRIMARY KEY?
- A table can have many primary keys but only one UNIQUE constraint
- A table has one primary key, which can never be NULL; it can have several UNIQUE constraints, whose columns may hold NULL in most databases
- UNIQUE columns cannot be indexed
- A primary key allows duplicate values
Show the answer
B. A table has one primary key, which can never be NULL; it can have several UNIQUE constraints, whose columns may hold NULL in most databases
Both forbid duplicates. The primary key identifies each row and is NOT NULL by definition; UNIQUE columns are alternate keys such as an email address.
This topic is named in a candidate’s interview report: Graduate analyst on-campus interview, 2022, on GeeksforGeeks.
-
Which of these is a DML command rather than a DDL command?
- CREATE
- ALTER
- DROP
- UPDATE
Show the answer
D. UPDATE
DML (data manipulation) changes the rows: INSERT, UPDATE, DELETE and, by most definitions, SELECT. DDL (data definition) changes the structure: CREATE, ALTER, DROP and TRUNCATE.
This topic is named in a candidate’s interview report: Graduate analyst on-campus interview, 2023, on GeeksforGeeks.
-
What is a trigger in SQL?
- A query that runs on a schedule, such as every night
- Code the database runs automatically when a chosen event, such as an INSERT, UPDATE or DELETE on a table, happens
- A constraint that stops NULL values
- Another name for a stored procedure the user calls by hand
Show the answer
B. Code the database runs automatically when a chosen event, such as an INSERT, UPDATE or DELETE on a table, happens
A trigger can run BEFORE or AFTER the event, for example to write an audit row whenever a salary changes. A stored procedure, by contrast, runs only when it is called.
This topic is named in a candidate’s interview report: Graduate analyst on-campus interview, 2020, on GeeksforGeeks.
-
Which statement about SQL and NoSQL databases is most accurate?
- SQL databases cannot run on more than one machine
- NoSQL databases cannot store structured data
- SQL databases store tables with a fixed schema, joins and strong transactions; NoSQL databases (document, key-value, column, graph) trade some of that for flexible schemas and easy horizontal scaling
- NoSQL means the database has no query language
Show the answer
C. SQL databases store tables with a fixed schema, joins and strong transactions; NoSQL databases (document, key-value, column, graph) trade some of that for flexible schemas and easy horizontal scaling
Choose SQL when data is relational and correctness across rows matters, as in payments. NoSQL suits flexible, very large or simple-lookup data, such as sessions in a key-value store.
This topic is named in a candidate’s interview report: Graduate analyst on-campus interview, 2023, on GeeksforGeeks.
-
emp(id, name) has ids with gaps, such as 3, 7, 8, 12, 15 and 20. Which query returns the 2nd, 4th, 6th ... rows in id order?
- SELECT * FROM emp WHERE id % 2 = 0;
- SELECT * FROM emp ORDER BY id LIMIT 2;
- SELECT id, name FROM (SELECT id, name, ROW_NUMBER() OVER (ORDER BY id) AS rn FROM emp) t WHERE rn % 2 = 0;
- SELECT * FROM emp ORDER BY id DESC LIMIT 3;
Show the answer
C. SELECT id, name FROM (SELECT id, name, ROW_NUMBER() OVER (ORDER BY id) AS rn FROM emp) t WHERE rn % 2 = 0;
ROW_NUMBER numbers the rows 1, 2, 3 ... in id order whatever the ids are, so rn % 2 = 0 keeps every second row: ids 7, 12 and 20. Testing id % 2 = 0 keeps the even ids (8, 12, 20), which only matches when the ids have no gaps.
This topic is named in a candidate’s interview report: Graduate analyst on-campus interview, 2023, on GeeksforGeeks.
-
How does a materialized view differ from an ordinary view?
- It cannot be queried
- It holds exactly one row
- It is a table with no query behind it
- It stores its query's result on disk, so reads are fast but the data can be out of date until it is refreshed; an ordinary view runs its query each time it is used
Show the answer
D. It stores its query's result on disk, so reads are fast but the data can be out of date until it is refreshed; an ordinary view runs its query each time it is used
A materialized view suits heavy reports over data that may lag a little, such as daily sales totals. It costs storage and refresh time. An ordinary view stores only the query, so it is always current and costs a query on every read.
This topic is named in a candidate’s interview report: Graduate analyst on-campus interview, 2020, on GeeksforGeeks.
-
emp.dept_id references dept(id) with ON DELETE CASCADE, and foreign keys are enforced. dept has ids 10 and 20; emp has 3 rows in dept 10 and 2 in dept 20. How many rows are left in emp after this?
DELETE FROM dept WHERE id = 10;- 5
- None: the DELETE fails
- 3
- 2
Show the answer
D. 2
CASCADE deletes the 3 employees of department 10 along with it, leaving 2. With the default (NO ACTION or RESTRICT) the DELETE would fail while any employee still points at 10, which is referential integrity at work. SQLite checks foreign keys only after PRAGMA foreign_keys = ON.
This topic is named in a candidate’s interview report: Graduate analyst on-campus interview, 2022, on GeeksforGeeks.
-
a(id) holds 1, 2, 3, 4 and b(id) holds 3, 4, 5. Which query returns only the ids found in both?
- SELECT id FROM a UNION SELECT id FROM b;
- SELECT id FROM a EXCEPT SELECT id FROM b;
- SELECT id FROM a, b;
- SELECT id FROM a INTERSECT SELECT id FROM b;
Show the answer
D. SELECT id FROM a INTERSECT SELECT id FROM b;
INTERSECT keeps rows present in both results: 3 and 4. UNION merges them (1 to 5), EXCEPT keeps what is only in a (1 and 2), and the comma join makes every pair and fails on the ambiguous id. An inner join on a.id = b.id, or WHERE id IN (SELECT id FROM b), also works.
This topic is named in a candidate’s interview report: Graduate analyst on-campus interview, 2020, on GeeksforGeeks.
-
Inside a stored procedure, an INSERT fails with a duplicate-key error. What lets the procedure catch the error and roll back cleanly instead of stopping?
- A WHERE clause
- An exception handler: DECLARE ... HANDLER in MySQL, EXCEPTION WHEN in PL/SQL and PL/pgSQL, or TRY...CATCH in SQL Server
- A view
- An index
Show the answer
B. An exception handler: DECLARE ... HANDLER in MySQL, EXCEPTION WHEN in PL/SQL and PL/pgSQL, or TRY...CATCH in SQL Server
The handler can roll the transaction back, log the problem or return a clear message, much as try/catch does in application code. Without one, the error ends the procedure and the caller must clean up.
This topic is named in a candidate’s interview report: Graduate analyst on-campus interview, 2020, on GeeksforGeeks.