Ericsson interview prep
9 practice questions on the topics candidates reported from Ericsson interviews, with answers. The questions are ours; each one links to the interview report that names its topic.
DSA 4
-
Which data structure is the natural fit for checking whether brackets like ([]{}) are balanced?
- A stack
- A queue
- A hash set
- A binary search tree
Show the answer
A. A stack
Push each opening bracket. Each closing bracket must match the bracket on top, which is popped. The string is balanced if every bracket matched and the stack ends empty.
This topic is named in a candidate’s interview report: Software developer interview, 2021, on Code360.
-
You are given a pointer to a node in a singly linked list, not the last node, but not the head. How do you delete that node?
- Walk back to the previous node and relink it
- Set the node pointer to null
- Copy the next node's data into this node, then unlink and free the next node
- It cannot be done without the head
Show the answer
C. Copy the next node's data into this node, then unlink and free the next node
You cannot reach the previous node, so you make this node a copy of its successor and remove the successor instead. It does not work for the tail, which has no successor.
This topic is named in a candidate’s interview report: Network security off-campus interview, 2023, on Code360.
-
How do you sort an array of only 0s, 1s and 2s in one pass with O(1) extra space?
- Use merge sort
- Three pointers (low, mid, high): a 0 at mid swaps to low, a 2 swaps to high, a 1 just moves mid on
- Count the values in a second array of size n
- It cannot be done in one pass
Show the answer
B. Three pointers (low, mid, high): a 0 at mid swaps to low, a 2 swaps to high, a 1 just moves mid on
This is Dijkstra's Dutch national flag partition. Everything before low is 0, everything after high is 2, and mid scans the unknown middle; after swapping with high, mid stays put because the swapped-in value is not yet checked.
This topic is named in a candidate’s interview report: Network security off-campus interview, 2023, on Code360.
-
You merge two sorted linked lists of lengths n and m into one sorted list by relinking their nodes. What does it cost?
- O(n * m) time
- O(n + m) time and O(1) extra space
- O((n + m) log(n + m)) time
- O(n + m) extra space
Show the answer
B. O(n + m) time and O(1) extra space
Compare the two heads, link the smaller to the tail of the result, advance that list, and attach whatever remains at the end. Each node is visited once and no node is copied; a dummy head node removes the special case for the first link.
This topic is named in a candidate’s interview report: Software developer interview, 2021, on Code360.
DBMS and SQL 2
-
Which query returns the second-highest salary in emp?
- SELECT MAX(salary) FROM emp WHERE salary < (SELECT MAX(salary) FROM emp);
- SELECT salary FROM emp ORDER BY salary LIMIT 2;
- SELECT MAX(salary) - 1 FROM emp;
- SELECT SECOND(salary) FROM emp;
Show the answer
A. SELECT MAX(salary) FROM emp WHERE salary < (SELECT MAX(salary) FROM emp);
The subquery finds the top salary, and the outer MAX finds the largest one below it. It also handles ties at the top correctly.
This topic is named in a candidate’s interview report: Assistant engineer trainee on-campus interview, 2023, on Code360.
-
How does TRUNCATE TABLE differ from DELETE FROM a table with no WHERE?
- They are identical in every database
- TRUNCATE drops the table definition too
- DELETE cannot remove every row
- TRUNCATE removes every row at once without logging each one or firing row triggers, and usually cannot take a WHERE
Show the answer
D. TRUNCATE removes every row at once without logging each one or firing row triggers, and usually cannot take a WHERE
DELETE removes rows one by one, can filter with WHERE and fires row triggers. TRUNCATE deallocates the data in bulk, which is much faster on big tables, and the table itself remains. Whether it can be rolled back depends on the database.
This topic is named in a candidate’s interview report: Assistant engineer trainee on-campus interview, 2023, on Code360.
Computer networks 2
-
How do the layers of the TCP/IP model line up with the OSI model?
- TCP/IP has the same seven layers
- TCP/IP's application layer covers OSI application, presentation and session; transport and internet match OSI transport and network; the link layer covers data link and physical
- TCP/IP has no transport layer
- OSI is what the internet runs on; TCP/IP is only a teaching model
Show the answer
B. TCP/IP's application layer covers OSI application, presentation and session; transport and internet match OSI transport and network; the link layer covers data link and physical
It is the other way round for the last option: the internet runs TCP/IP, and OSI is the seven-layer reference model used to talk about it. HTTP sits in TCP/IP's application layer, TCP and UDP in transport, IP in the internet layer, Ethernet and Wi-Fi in the link layer.
This topic is named in a candidate’s interview report: Network security off-campus interview, 2023, on Code360.
-
A router has routes for 10.0.0.0/8, 10.1.0.0/16 and 10.1.2.0/24. Which route does a packet to 10.1.2.5 take?
- 10.0.0.0/8
- 10.1.2.0/24
- 10.1.0.0/16
- All three, in turn
Show the answer
B. 10.1.2.0/24
All three prefixes match, and the router picks the longest, most specific one: /24. Longest prefix matching is what lets a broad route cover a block while a narrower route overrides part of it; routers do it in hardware with tries or TCAM.
This topic is named in a candidate’s interview report: Network security off-campus interview, 2023, on Code360.
Aptitude 1
-
All mangoes are fruits, and some fruits are sour. Which conclusion must follow?
- Some mangoes are sour
- All fruits are mangoes
- No mango is sour
- None of these must follow
Show the answer
D. None of these must follow
The sour fruits might all be other fruits, so "some mangoes are sour" is possible but not certain, and so is "no mango is sour". "All fruits are mangoes" reverses the first statement. Drawing the sets as circles makes this quick.
This topic is named in a candidate’s interview report: Assistant engineer trainee on-campus interview, 2023, on Code360.