r/InterviewDB • u/interviewdb • 2d ago
Confluent SWE Coding Assessment Questions (75 minutes, 2 questions)
Sharing two coding questions from a recent Confluent coding assessment. The time limit was 75 minutes.
Question 1
Object collision on the table: given a list of object position, velocity and table length, calculate the last object on the table. Positive velocity moves right, negative moves left,. During collision, velocity will exchange Eg. position: [2, 4, 5], velocity [2, -2, 4] table length 9, object 1 and 2 will collide at position 3, at 0.5 seconds. The last object on the table is object 2, 0.5 before collision and (9-3)/2 after collision, at 3.5 Return round up value as 4.
This is the classic "ants on a plank" problem. The trick is that exchanging velocities in a collision looks exactly like the two objects passing through each other. So you can ignore collisions completely when computing when the last object falls off.
Question 2
Function C(i,j) =i mod j + j mod i. We need to calculate sum of C(i,j) for all pair of 1 <= i <= n, 1 <= j<= n. Function input is n (1 <= n <= 10^6), return result module (10^9+7).
For example, when n = 2, result = C(1,1) + C(1, 2) + C(2,1)+ C(2,2) = 0+1+1+0=2
This question requires some mathematical observations. Example code:
def calculate_checksum(limit: int) -> int:
PRIME_MOD = 1000000007
cumulative_sum = 0
# Iterate through each divisor step from 1 to the given limit
for step in range(1, limit + 1):
multiplier = limit // step
leftover = limit % step
# Contribution from full repetition cycles
full_cycle_total = (multiplier * (step * (step - 1) // 2)) % PRIME_MOD
# Contribution from the remaining partial cycle
partial_cycle_total = (leftover * (leftover + 1) // 2) % PRIME_MOD
# Combine totals for the current step
step_total = (full_cycle_total + partial_cycle_total) % PRIME_MOD
cumulative_sum = (cumulative_sum + step_total) % PRIME_MOD
# Account for both sides of the symmetric pairs
final_answer = (2 * cumulative_sum) % PRIME_MOD
return final_answer