HSBC interview prep
4 practice questions on the topics candidates reported from HSBC interviews, with answers. The questions are ours; each one links to the interview report that names its topic.
DSA 2
-
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: Technology off-campus interview, 2023, 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: Technology off-campus interview, 2023, on GeeksforGeeks.
Python 1
-
What does this print?
def is_pal(s): i, j = 0, len(s) - 1 while i < j: if s[i] != s[j]: return False i, j = i + 1, j - 1 return True print(is_pal("racecar"), is_pal("racecars"))- True True
- False True
- True False
- False False
Show the answer
C. True False
Two indices move inwards comparing characters. racecar matches all the way; racecars fails at once because r and s differ. This needs no extra copy, unlike s == s[::-1].
This topic is named in a candidate’s interview report: Technology off-campus interview, 2023, on GeeksforGeeks.
Operating systems 1
-
Which Linux command lists the files in the current directory sorted by last modification time, newest first?
- ls -S
- ls -t
- sort -t
- ls -r
Show the answer
B. ls -t
ls -t sorts by modification time, newest first, and ls -S by size, largest first. -r reverses either order. sort sorts lines of text, for example ls -l | sort -k5 -n.
This topic is named in a candidate’s interview report: Trainee software engineer interview, 2023 batch, on GeeksforGeeks.