IBM Online Assessment -On Campus-2 Coding Problems
I recently completed an IBM Online Assessment and wanted to share the coding questions I encountered.
Platform:HackerRank
Time:70 minutes
Question 1 – Make the Array Alternating in Parity
Given an array of positive integers, find the minimum number of operations required to make the array alternate in parity.
The final array can follow either of these patterns:
Odd, Even, Odd, Even, ...Even, Odd, Even, Odd, ...
Operation
In one operation, you can replace any element:
nums[i] = floor(nums[i] / 2)
You can perform the operation on the same element multiple times.
Example
nums = [6, 12, 5, 10]For the pattern:
Even, Odd, Even, OddWe can transform:
6 -> 6 (Even)
12 -> 6 -> 3 (Odd) -> 2 operations
5 -> 2 (Even) -> 1 operation
10 -> 10 (Even)So the total is:
3 operations
For the pattern:
odd, even, odd, evenWe can transform:
6 -> 3 (odd) -> 1 operations
12 -> (Even)
5 -> 2 (odd)
10 -> 10 (Even)So the answer is:
1 operationAnother example:
nums = [3, 12, 5, 10]The array is already:
Odd, Even, Odd, Evenso the answer is:
0If considering a transformation such as:
6 -> 3that costs one operation.
Constraints
1 <= nums.size() < 10^5
nums[i] > 0Question 2 – Maximum Number of Valid Pairs
Given two arrays arr1 and arr2, and an integer d, form the maximum number of pairs (arr1[i], arr2[j]) satisfying:
arr1[i] <= arr2[j] <= arr1[i] + dEach element can be used in at most one pair.
Example
arr1 = [8, 20, 35, 45]
arr2 = [25, 50]
d = 10Possible valid pairs include:
(20, 25) because 20 <= 25 <= 30
(45, 50) because 45 <= 50 <= 55Therefore:
Answer = 2Constraints
1 <= arr1.size(), arr2.size() <= 10^5
1 <= d <= 10^5These were the two coding questions I encountered in my IBM OA.
I used AI tool to enhance the post but the question I share is based on my personal recollection
I takes some valuable time to write this post so i requested to like ,share and also I am available to answer any comments.
IBM OA Experience – On Campus-Two Coding Questions


