Mastercard interview prep
20 practice questions on the topics candidates reported from Mastercard interviews, with answers. The questions are ours; each one links to the interview report that names its topic.
DSA 4
-
An array holds the numbers from 1 to 8 with exactly one missing: [3, 7, 1, 2, 8, 4, 5]. Using the formula for the sum 1 + 2 + ... + n, which number is missing?
- 5
- 9
- 4
- 6
Show the answer
D. 6
The full sum is 8 * 9 / 2 = 36 and the array adds up to 30, so 6 is missing. XORing 1 to n with every array element gives the same answer without any risk of overflow.
This topic is named in a candidate’s interview report: SDE on-campus interview, 2024, on GeeksforGeeks.
-
You reverse a singly linked list in place by walking it once with three pointers, prev, curr and next. At each node, what do you do?
- Save next = curr.next, point curr.next at prev, then move prev to curr and curr to next
- Swap the node's value with the value at the other end of the list
- Push every node onto a stack, then pop them all
- Point curr.next at curr.next.next
Show the answer
A. Save next = curr.next, point curr.next at prev, then move prev to curr and curr to next
Saving next first keeps the rest of the list reachable after the link is turned round. When curr becomes null, prev is the new head. One pass, O(n) time, O(1) extra space.
This topic is named in a candidate’s interview report: SDE intern interview, 2024, on GeeksforGeeks.
-
A singly linked list is circular if its last node points back to the head. How do you check that with no extra memory?
- Walk from head.next until you reach null (not circular) or the head again (circular)
- Count the nodes and compare with a stored length
- Sort the list and look for duplicates
- Check whether the head's value appears twice
Show the answer
A. Walk from head.next until you reach null (not circular) or the head again (circular)
For a list that is either a plain list or a full circle, one walk settles it in O(n) time and O(1) space. If the loop could start in the middle instead, a walk would never meet the head again, and you need fast and slow pointers (Floyd) to find it.
This topic is named in a candidate’s interview report: SDE intern interview, 2024, on GeeksforGeeks.
-
Scanning [12, 35, 1, 10, 34, 1] once while keeping the largest and the second largest distinct values, what is the second largest?
- 35
- 34
- 12
- 10
Show the answer
B. 34
Keep first and second. A value above first pushes first down to second; a value between them replaces second; equal values are skipped so a repeated maximum is not counted twice. One pass, O(n) time and O(1) space, with no sorting.
This topic is named in a candidate’s interview report: SDE on-campus interview, 2024, on GeeksforGeeks.
Java 3
-
What does this print?
public class Main { public static void main(String[] args) { String a = "ust"; String b = "ust"; String c = new String("ust"); System.out.println((a == b) + " " + (a == c) + " " + a.equals(c)); } }- true true true
- true false false
- false false true
- true false true
Show the answer
D. true false true
String literals are interned in the String pool, so a and b are the same object. new String always makes a new object outside the pool, so a == c is false. equals compares the characters, so it is true. c.intern() would return the pooled one.
This topic is named in a candidate’s interview report: SDE intern interview, 2024, on GeeksforGeeks.
-
Two threads call a synchronized method on the same Java object at the same moment. What happens?
- Both run it together
- One thread takes the object's lock and runs it; the other waits until the lock is released
- The second call is dropped
- Java throws a ConcurrentModificationException
Show the answer
B. One thread takes the object's lock and runs it; the other waits until the lock is released
synchronized makes the object's monitor a mutex: only one thread holds it at a time, and releasing it also makes that thread's writes visible to the next. A static synchronized method locks the Class object instead. java.util.concurrent offers ReentrantLock for finer control.
This topic is named in a candidate’s interview report: SDE on-campus interview, 2024, on GeeksforGeeks.
-
Why is Java called platform independent?
- Java programs need no runtime
- javac compiles to bytecode, and any machine with a JVM runs the same .class files
- Java source is compiled again on every machine
- Java can only run in a browser
Show the answer
B. javac compiles to bytecode, and any machine with a JVM runs the same .class files
The bytecode is the same everywhere; the JVM is what is built for each operating system and CPU, and it interprets or JIT-compiles the bytecode. "Write once, run anywhere" holds as long as the code avoids platform-specific native calls.
This topic is named in a candidate’s interview report: SDE on-campus interview, 2022, on GeeksforGeeks.
Python 2
-
What does this print?
def is_rotation(a, b): return len(a) == len(b) and b in a + a print(is_rotation("waterbottle", "erbottlewat"), is_rotation("abc", "acb"))- True True
- True False
- False True
- False False
Show the answer
B. True False
Every rotation of a is a substring of a + a: "waterbottlewaterbottle" contains "erbottlewat". "acb" is a reordering, not a rotation, so it does not appear in "abcabc". The length check stops a shorter string from matching.
This topic is named in a candidate’s interview report: SDE intern interview, 2024, on GeeksforGeeks.
-
Why does indentation matter in Python but not in C?
- It is only a style rule in both
- Python marks a block by its indentation, where C uses braces; a wrongly indented line changes which block it belongs to, or is an IndentationError
- C forbids indentation
- Python ignores indentation inside functions
Show the answer
B. Python marks a block by its indentation, where C uses braces; a wrongly indented line changes which block it belongs to, or is an IndentationError
After a line ending in a colon, Python expects an indented block, and the block ends where the indentation returns. In C the compiler reads braces and semicolons, so indentation only helps the reader.
This topic is named in a candidate’s interview report: SDE on-campus interview, 2022, on GeeksforGeeks.
DBMS and SQL 6
-
When is a document database such as MongoDB usually a better fit than a relational database?
- When many tables must be joined with strict transactions across them
- When the data is a few small tables with a fixed structure
- Whenever the data must survive a restart
- When each record is read and written as a whole and its fields vary from record to record
Show the answer
D. When each record is read and written as a whole and its fields vary from record to record
A document keeps a record and its nested details together without one fixed schema, which suits catalogues, profiles and event logs. Relational databases are stronger when data is shared between tables and changes must span them in one transaction.
This topic is named in a candidate’s interview report: SDE on-campus interview, 2022, on GeeksforGeeks.
-
What does adding an index on a column usually do?
- Speeds up queries that search or sort on that column, at the cost of extra storage and slower inserts and updates
- Speeds up every query on the table, with no cost
- Prevents duplicate values in the column
- Compresses the table to save space
Show the answer
A. Speeds up queries that search or sort on that column, at the cost of extra storage and slower inserts and updates
A B-tree index lets the database find matching rows in O(log n) instead of scanning the table. Every write must also update the index, so indexes go on columns that are searched often. Only a UNIQUE index stops duplicates.
This topic is named in a candidate’s interview report: SDE on-campus interview, 2024, on GeeksforGeeks.
-
What does a FULL OUTER JOIN of tables A and B return?
- Only rows that match in both
- Every row from both tables: matched rows joined, and unmatched rows from either side with NULLs for the other side's columns
- Every row from A only
- Every combination of rows from A and B
Show the answer
B. Every row from both tables: matched rows joined, and unmatched rows from either side with NULLs for the other side's columns
INNER keeps matches only, LEFT adds unmatched A rows, RIGHT adds unmatched B rows, FULL adds both. Every combination is a CROSS JOIN. MySQL has no FULL OUTER JOIN and emulates it with a LEFT JOIN UNION a RIGHT JOIN.
This topic is named in a candidate’s interview report: SDE on-campus interview, 2022, on GeeksforGeeks.
-
What is a stored procedure?
- A backup of a table
- A query the database runs automatically when a row changes
- A named block of SQL saved in the database, run with a call and able to take parameters
- An index on a view
Show the answer
C. A named block of SQL saved in the database, run with a call and able to take parameters
A procedure runs where the data is, so a multi-step job costs one round trip, and access can be granted to the procedure rather than the tables. A trigger is the one that runs automatically on an INSERT, UPDATE or DELETE.
This topic is named in a candidate’s interview report: SDE on-campus interview, 2022, on GeeksforGeeks.
-
A book can have several authors and an author can write several books. How do you model that in a relational database?
- Put an author_id column in books
- A third table, book_author(book_id, author_id), with a foreign key to each table and the pair as its primary key
- Put a book_id column in authors
- Store the author names as a list in one column of books
Show the answer
B. A third table, book_author(book_id, author_id), with a foreign key to each table and the pair as its primary key
A foreign key on either side can hold only one value per row, which is a one-to-many relationship. Many-to-many needs a junction table: one row per (book, author) pair. The list-in-a-column option also breaks first normal form.
This topic is named in a candidate’s interview report: SDE on-campus interview, 2024, on GeeksforGeeks.
-
Table a holds the values 1, 2, 2 and table b holds 2, 3. How many rows do the two queries return?
SELECT v FROM a UNION SELECT v FROM b; SELECT v FROM a UNION ALL SELECT v FROM b;- 3 and 5
- 3 and 3
- 5 and 5
- 2 and 5
Show the answer
A. 3 and 5
UNION removes duplicate rows from the combined result, leaving 1, 2, 3. UNION ALL keeps everything, all five rows, and is cheaper because it skips the de-duplication. Both need the same number of columns with compatible types.
This topic is named in a candidate’s interview report: SDE on-campus interview, 2022, on GeeksforGeeks.
Operating systems 2
-
How does a mutex differ from a counting semaphore?
- A mutex lets one holder in at a time and is released by its owner; a semaphore allows up to N and anyone may signal it
- They are two names for the same thing
- A semaphore can only be used between processes
- A mutex lets N threads in at once
Show the answer
A. A mutex lets one holder in at a time and is released by its owner; a semaphore allows up to N and anyone may signal it
A mutex is for mutual exclusion over one resource, owned by the thread that locked it. A counting semaphore counts available slots, such as 5 database connections, and is also used for signalling between threads.
This topic is named in a candidate’s interview report: SDE on-campus interview, 2024, on GeeksforGeeks.
-
Which statement about stack and heap memory is true?
- The stack holds each call's frame (locals, return address) and is freed when the call returns; the heap holds memory allocated at run time that lives until it is freed or collected
- Heap memory is freed automatically when a function returns
- The stack is always larger than the heap
- Only global variables live on the stack
Show the answer
A. The stack holds each call's frame (locals, return address) and is freed when the call returns; the heap holds memory allocated at run time that lives until it is freed or collected
Stack allocation is a pointer bump and is undone on return, which is why returning the address of a local is a bug. Heap memory (malloc, new) outlives the call and must be freed, or in Java and Python reclaimed by the garbage collector. Deep recursion overflows the stack, not the heap.
This topic is named in a candidate’s interview report: SDE intern on-campus interview, 2023, on GeeksforGeeks.
Computer networks 1
-
Which HTTP method is NOT idempotent?
- GET
- PUT
- DELETE
- POST
Show the answer
D. POST
Repeating a PUT or DELETE leaves the server in the same state, but repeating a POST can create a second order. That is why payment APIs add idempotency keys.
This topic is named in a candidate’s interview report: SDE on-campus interview, 2024, on GeeksforGeeks.
Web development 2
-
In React, how do props differ from state?
- They are the same object
- Props are passed in by the parent and read-only to the child; state is owned by the component and changed with its setter, which re-renders it
- State is passed in by the parent; props are private
- Props can only hold strings
Show the answer
B. Props are passed in by the parent and read-only to the child; state is owned by the component and changed with its setter, which re-renders it
Data flows down: a parent keeps state and passes values (and callbacks) as props. A child that needs to change the parent's data calls a callback it was given; it never assigns to its props.
This topic is named in a candidate’s interview report: SDE intern on-campus interview, 2023, on GeeksforGeeks.
-
What is React's virtual DOM for?
- It is a second browser that runs React
- React renders to a lightweight tree in memory, compares it with the previous one, and applies only the differences to the real DOM
- It stores the page offline
- It makes React run on the server only
Show the answer
B. React renders to a lightweight tree in memory, compares it with the previous one, and applies only the differences to the real DOM
Touching the real DOM is the slow part, so React batches and minimises it. This diffing step is called reconciliation, and keys on list items tell React which item is which so it can move elements instead of rebuilding them.
This topic is named in a candidate’s interview report: SDE intern on-campus interview, 2023, on GeeksforGeeks.