CHUBB OA 2026 (Campus Placement)

chubb logo
chubb
· SDE I
September 28, 2026 · 0 reads

Summary

I completed the Chubb online assessment, which consisted of five algorithmic problems, and provided optimal solutions for each.

Full Experience

Chubb OA | SDE | 5 Questions (With Optimal Solutions)

Just finished my Online Assessment for Chubb. It consisted of 5 questions ranging from simple array manipulations to dynamic programming/greedy concepts. Here are the exact problem statements, examples, and the optimal textual solutions to help everyone prepare.

Problem 1: Modified Knapsack (Powers of 2 Weights) Problem Statement: You are given a cost array where the weight of the i-th element is strictly 2^i (0-indexed). You are also given a target minWeight. You can pick any element multiple times. Find the minimum total cost to achieve a combined weight of at least minWeight. Example:

  • cost = [2, 5, 7, 11, 25]
  • minWeight = 26
  • Output: 37 Same problem on CodeForces : 913C Party Lemonade

Optimal Solution (O(N) Time, O(1) Space): Standard DP will result in TLE/MLE because minWeight can be huge. Instead, use a Greedy Bitmasking approach. First, normalize the cost array so that a larger weight never costs more than two of the preceding weights: cost[i] = min(cost[i], 2 * cost[i-1]). Then, iterate from the highest possible bit down to 0. If the bit is set in minWeight, add its cost to a running sum. If the bit is 0, check if picking this item anyway (which covers all remaining lower bits) yields a cheaper overall cost than the running sum.


Problem 2: Sprint Training (Most Visited Marker) Problem Statement: You are given N markers on a track (numbered 1 to N) and an array of sprints. Each adjacent pair in the sprints array represents the starting and ending points of a sprint (which can run forwards or backwards). Return the lowest numbered marker that is visited the maximum number of times across all sprints. Example:

  • n = 5
  • sprints = [2, 4, 1, 3]
  • Output: 2
  • Explanation: 2->4 : 2,3,4 4->1 : 1,2,3,4 1->3 : 1,2,3 visited = [2,3,3,2,0] ans = 2 (visited 3 times, 3rd marker also visited 3 times but we want lowest among them)

Optimal Solution (O(N + M) Time, O(N) Space): Avoid simulating every step of every sprint. Use a Difference Array (Sweep Line). For a sprint from A to B, find start = min(A, B) and end = max(A, B). Increment diff[start] by 1 and decrement diff[end + 1] by 1. Finally, compute the prefix sum of the diff array from 1 to N. The prefix sum at index i gives the exact number of times marker i was visited. Track the maximum value and return the lowest index.


Problem 3: JSON Diff Problem Statement: You are given two fully stringified JSON objects representing flat key-value pairs. Parse both JSON strings and return a sorted list of all keys that are present in both JSONs but have different values. Example:

  • json1 = '{"name":"John", "age":"30", "status":"active"}'
  • json2 = '{"name":"John", "age":"31", "status":"inactive", "role":"admin"}'
  • Output: ["age","status"]

Optimal Solution (O(N log N) Time, O(N) Space): Clean the strings by removing curly braces, split by commas to isolate the pairs, and split by colons to separate keys from values (stripping whitespace and quotes). Store both in HashMaps. Iterate through the keys of the first map, check if they exist in the second map, and compare the string values. Store differing keys in a list and sort it lexicographically before returning.


Problem 4: Array Operations (Extract Last Element) Problem Statement: You are given two arrays, current and desired (both contain the same elements). You can perform exactly one type of operation: extract the last element of the current array and insert it anywhere in the array. Find the minimum number of operations required to transform current into desired. Example:

  • current = [2, 1, 3, 5, 4]
  • desired = [2, 4, 1, 5, 3]
  • Output: 2
  • Explanation: Move 4 and insert it to get [2, 4, 1, 3, 5]. Move 5 and insert it to get [2, 4, 1, 5, 3].

Optimal Solution (O(N) Time, O(1) Space): Because you can only extract from the end, any elements you choose to leave untouched must form a contiguous prefix in the current array. Furthermore, to avoid moving them, they must appear in the exact same relative order in the desired array. Therefore, use a two-pointer approach to find the length of the longest prefix of current that is a valid subsequence of desired. The minimum operations required is simply Total Length - Length of this prefix.


Problem 5: Maximum Student-Teacher Distance Problem Statement: There are N students sitting in a line at indices 0 to N - 1. You are given an array pos representing the indices where teachers are standing. For each teacher at index p, the teacher assigns a value of 0 to the student at index p. For all other students, the assigned value increases by +1 for each step moving to the left of p, and similarly increases by +1 for each step moving to the right of p. A student's final score is the maximum value they receive across all teachers. Return an array of these maximum values for all students. Example:

  • N = 5
  • pos = [3, 0, 1, 4]
  • Output: [4, 3, 2, 3, 4]
  • Explanation: Teacher at 3 assigns values: [3, 2, 1, 0, 1] Teacher at 0 assigns values: [0, 1, 2, 3, 4] Teacher at 1 assigns values: [1, 0, 1, 2, 3] Teacher at 4 assigns values: [4, 3, 2, 1, 0] The maximum value each student receives across all teachers is [4, 3, 2, 3, 4].

Optimal Solution (O(N + P) Time, O(1) Extra Space): Notice that the process of assigning 0 at index p and increasing by +1 in both directions is mathematically identical to calculating the absolute distance: |i - p|. Do not simulate the distance from every student to every teacher (which takes O(N * P)), and avoid simulating the decay from the edges (which fails when teachers are grouped on one side). Because absolute distance is a linear function, the furthest teacher from any student will always be the teacher standing at the absolute minimum position or the absolute maximum position. Find min(pos) and max(pos) in one pass. Then, for each student i, their answer is simply max(abs(i - min(pos)), abs(i - max(pos))).

Interview Questions (5)

1.

Modified Knapsack (Powers of 2 Weights)

Data Structures & Algorithms

You are given a cost array where the weight of the i-th element is strictly 2^i (0-indexed). You are also given a target minWeight. You can pick any element multiple times. Find the minimum total cost to achieve a combined weight of at least minWeight. Example:

  • cost = [2, 5, 7, 11, 25]
  • minWeight = 26
  • Output: 37
2.

Sprint Training (Most Visited Marker)

Data Structures & Algorithms

You are given N markers on a track (numbered 1 to N) and an array of sprints. Each adjacent pair in the sprints array represents the starting and ending points of a sprint (which can run forwards or backwards). Return the lowest numbered marker that is visited the maximum number of times across all sprints. Example:

  • n = 5
  • sprints = [2, 4, 1, 3]
  • Output: 2
  • Explanation: 2->4 : 2,3,4; 4->1 : 1,2,3,4; 1->3 : 1,2,3; visited = [2,3,3,2,0]; ans = 2 (visited 3 times, 3rd marker also visited 3 times but we want lowest among them).
3.

JSON Diff

Data Structures & Algorithms

You are given two fully stringified JSON objects representing flat key-value pairs. Parse both JSON strings and return a sorted list of all keys that are present in both JSONs but have different values. Example:

  • json1 = '{"name":"John", "age":"30", "status":"active"}'
  • json2 = '{"name":"John", "age":"31", "status":"inactive", "role":"admin"}'
  • Output: ["age","status"]
4.

Array Operations (Extract Last Element)

Data Structures & Algorithms

You are given two arrays, current and desired (both contain the same elements). You can perform exactly one type of operation: extract the last element of the current array and insert it anywhere in the array. Find the minimum number of operations required to transform current into desired. Example:

  • current = [2, 1, 3, 5, 4]
  • desired = [2, 4, 1, 5, 3]
  • Output: 2
  • Explanation: Move 4 and insert it to get [2, 4, 1, 3, 5]. Move 5 and insert it to get [2, 4, 1, 5, 3].
5.

Maximum Student-Teacher Distance

Data Structures & Algorithms

There are N students sitting in a line at indices 0 to N - 1. You are given an array pos representing the indices where teachers are standing. For each teacher at index p, the teacher assigns a value of 0 to the student at index p. For all other students, the assigned value increases by +1 for each step moving to the left of p, and similarly increases by +1 for each step moving to the right of p. A student's final score is the maximum value they receive across all teachers. Return an array of these maximum values for all students. Example:

  • N = 5
  • pos = [3, 0, 1, 4]
  • Output: [4, 3, 2, 3, 4]

📣 Found this helpful? Please share it with friends who are preparing for interviews!

Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

Be the first to share your thoughts and start the discussion!