GlobalLogic interview prep
9 practice questions on the topics candidates reported from GlobalLogic interviews, with answers. The questions are ours; each one links to the interview report that names its topic.
DSA 4
-
The positive numbers divisible by 2 or by 3, in order, are 2, 3, 4, 6, 8, 9, ... What is the 10th one?
- 14
- 15
- 16
- 18
Show the answer
B. 15
Listing them: 2, 3, 4, 6, 8, 9, 10, 12, 14, 15. For large n, binary search on x with count(x) = x/2 + x/3 - x/6 finds the answer without listing.
This topic is named in a candidate’s interview report: On-campus interview, 2017, on GeeksforGeeks.
-
An array holds only the values 3, 4 and 5, in any order. What sorts it in a single pass with O(1) extra space?
- Merge sort
- Building a balanced binary search tree
- Bubble sort with an early exit
- Dutch national flag partitioning with three pointers (low, mid, high)
Show the answer
D. Dutch national flag partitioning with three pointers (low, mid, high)
mid scans the array: a 3 is swapped to low, a 5 to high, a 4 is left in place. Each element is handled once, so the pass is O(n) with three indices of extra space.
This topic is named in a candidate’s interview report: On-campus interview, 2017, on GeeksforGeeks.
-
The diameter of a binary tree is the number of edges on the longest path between any two nodes. A root has a left child L and a right child R, and L has a left child LL. What is the diameter?
- 2
- 1
- 4
- 3
Show the answer
D. 3
The longest path is LL - L - root - R, which has 3 edges. In general, for each node take (height of left subtree) + (height of right subtree) and keep the maximum, all in one O(n) traversal.
This topic is named in a candidate’s interview report: Pool campus interview, 2019, on GeeksforGeeks.
-
Mirroring a binary tree swaps the left and right children of every node. If a tree's in-order traversal is 1 2 3 4 5, what is the in-order traversal of its mirror?
- 1 2 3 4 5
- 5 4 3 2 1
- 3 2 1 5 4
- 1 3 5 2 4
Show the answer
B. 5 4 3 2 1
In-order visits left, node, right. In the mirror every left and right are exchanged, so the same visit happens in exactly the reverse order.
This topic is named in a candidate’s interview report: Pool campus interview, 2019, on GeeksforGeeks.
Python 3
-
What does this print?
a, b = 5, 9 a = a + b b = a - b a = a - b print(a, b)- 5 9
- 14 5
- 9 5
- 9 14
Show the answer
C. 9 5
After a = a + b, a is 14. b = 14 - 9 = 5, the old a. a = 14 - 5 = 9, the old b. The values are swapped without a third variable (in fixed-size integer languages the sum can overflow, which is why XOR swaps are also taught).
This topic is named in a candidate’s interview report: Software engineer trainee interview, 2023, on GeeksforGeeks.
-
What does this print?
s = " I love coding " print(" ".join(s.split()[::-1]))- coding love I
- gnidoc evol I
- coding love I
- I love coding
Show the answer
A. coding love I
split() with no argument splits on any run of whitespace and drops the empty pieces, giving ['I', 'love', 'coding']. [::-1] reverses the list and join puts single spaces back.
This topic is named in a candidate’s interview report: On-campus interview, 2017, on GeeksforGeeks.
-
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: Software engineer trainee interview, 2023, on GeeksforGeeks.
Aptitude 2
-
Nine balls look the same, but one is heavier. With a balance scale, what is the fewest number of weighings that always finds the heavy ball?
- 3
- 1
- 2
- 4
Show the answer
C. 2
Weigh 3 against 3. If they balance, the heavy ball is in the other 3; otherwise it is in the heavier group. Then weigh 1 against 1 from that group the same way. Each weighing has 3 outcomes, and 3 x 3 = 9.
This topic is named in a candidate’s interview report: On-campus interview, 2017, on GeeksforGeeks.
-
25 horses, a track that races 5 at a time and no timer. What is the minimum number of races needed to find the 3 fastest?
- 6
- 7
- 8
- 11
Show the answer
B. 7
5 heats rank every horse within its group. Race 6, the five heat winners, finds the fastest overall. Only 5 horses can still be second or third: the 2nd and 3rd of the winner's heat, the winner and 2nd of the runner-up's heat, and the winner of the 3rd-place heat. Race 7 settles them.
This topic is named in a candidate’s interview report: Pool campus interview, 2019, on GeeksforGeeks.