Aptiv interview prep
5 practice questions on the topics candidates reported from Aptiv interviews, with answers. The questions are ours; each one links to the interview report that names its topic.
DSA 4
-
Two singly linked lists join at some node and share every node after it. Two pointers walk the lists, and each jumps to the head of the other list when it reaches the end. Why do they meet at the joining node?
- Because the two lists always have the same length
- Before reaching the shared part, both have walked the same distance: the first list's own nodes plus the second list's own nodes plus the shared tail once
- Because one pointer moves twice as fast as the other
- They do not; this only detects a cycle
Show the answer
B. Before reaching the shared part, both have walked the same distance: the first list's own nodes plus the second list's own nodes plus the shared tail once
If the lists are a + c and b + c long, with c shared, one pointer walks a + c + b and the other b + c + a before entering the shared part, so they arrive together. O(m + n) time, O(1) space. If the lists never join, both reach null at the same moment.
This topic is named in a candidate’s interview report: Software engineer on-campus interview, 2022, on Code360.
-
What is the length of the longest common subsequence of "STONE" and "LONGEST"?
- 2
- 3
- 4
- 5
Show the answer
B. 3
dp[i][j] is the answer for the first i letters of one word and the first j of the other: equal letters give dp[i-1][j-1] + 1, otherwise the larger of dp[i-1][j] and dp[i][j-1]. "ONE" appears in order in both words. O(mn) time.
This topic is named in a candidate’s interview report: Software engineer off-campus interview, 2022, on Code360.
-
What is the length of the longest run of consecutive integers in [100, 4, 200, 1, 3, 2], in any order?
- 3
- 4
- 6
- 2
Show the answer
B. 4
1, 2, 3 and 4 are all present. Put every number in a hash set, start counting only from numbers whose predecessor is missing, and each number is visited a constant number of times: O(n).
This topic is named in a candidate’s interview report: Software engineer on-campus interview, 2022, on Code360.
-
Why is merge sort the usual choice for sorting a linked list?
- It needs random access to the middle element in O(1)
- It never needs random access: splitting uses slow and fast pointers and merging just relinks nodes, giving O(n log n) with no extra array
- It is the only stable sort
- It sorts a linked list in O(n)
Show the answer
B. It never needs random access: splitting uses slow and fast pointers and merging just relinks nodes, giving O(n log n) with no extra array
Quicksort and heapsort lean on indexing, which costs O(n) per access on a list. Merge sort only walks forward, and merging two sorted lists needs no copy of the data, just pointer changes.
This topic is named in a candidate’s interview report: Software engineer off-campus interview, 2022, on Code360.
C and C++ 1
-
What does this print?
#include <stdio.h> struct Point { int x, y; }; int main(void) { struct Point s = {5, 9}; struct Point *p = &s; p->x = 7; printf("%d %d\n", s.x, (*p).y); return 0; }- 5 9
- 7 9
- 7 7
- 5 7
Show the answer
B. 7 9
p points at s, so p->x = 7 changes s.x. p->x is shorthand for (*p).x; the brackets matter because . binds tighter than *.
This topic is named in a candidate’s interview report: Software engineer off-campus interview, 2022, on Code360.