FastPrepChecksum Aggregator
Problems/Checksum Aggregator

Checksum Aggregator

Fortinet logoFortinet● HardOA

Updated Jun 2025

QuestionFunctionExamplesConstraints

Problem statement

In a distributed network system, data packets with unique identifiers and checksum values are sent between nodes to maintain communication and data integrity. Develop a function to aggregate the checksum values for all possible pairs of packets within the network.

For any two distinct packets with identifiers i and j, the checksum is calculated as C(i, j) = i mod j + j mod i. Calculate the sum of C(i, j) for all pairs (1 <= i <= n) and (1 <= j <= n), where n is the total number of packets in the network. Return the result modulo (10 ** 9 + 7)

Function

computeChecksumAggregation(n: int) → int

Complete the function computeChecksumAggregation in the editor.

computeChecksumAggregation has the following parameter:

  1. int n: the total number of packets in the network

Returns

int: the aggregated checksum

My sincere thanks to da best friend for so generouly sharing the problem source! 🌷

Examples

Example 1

n = 3return = 10

Given n = 3, calculate the checksum for all the pairs of packets (i, j) where (1 <= i <= n) and (1 <= j <= n)

  • C(1, 1) = 1 mod 1 + 1 mod 1 = 0 + 0 = 0
  • C(1, 2) = 1 mod 2 + 2 mod 1 = 1 + 0 = 1
  • C(1, 3) = 1 mod 3 + 3 mod 1 = 1 + 0 = 1
  • C(2, 1) = 2 mod 1 + 1 mod 2 = 0 + 1 = 1
  • C(2, 2) = 2 mod 2 + 2 mod 2 = 0 + 0 = 0
  • C(2, 3) = 2 mod 3 + 3 mod 2 = 2 + 1 = 3
  • C(3, 1) = 3 mod 1 + 1 mod 3 = 0 + 1 = 1
  • C(3, 2) = 3 mod 2 + 2 mod 3 = 1 + 2 = 3
  • C(3, 3) = 3 mod 3 + 3 mod 3 = 0 + 0 = 0

The aggregated checksum is 0 + 1 + 1 + 1 + 0 + 3 + 1 + 3 + 0 = 10 mod (10 ** 9 + 7) = 10

Constraints

1 <= n <= 10 ** 6

More Fortinet interview questions

  • K-Means ClusteringOA · Seen Jun 2025
  • Madam C.J. Walker's Business PlanOA · Seen Jun 2025
  • Signal PingsOA · Seen Jun 2025
  • Maximize Beautiful SubstringsOA · Seen Mar 2025

Similar questions at other companies

  • Delete and Freeze GameRubrik · OARubrik interview questions
  • Lock CodeVisa · OAVisa interview questions
  • Bootstrap Decision Tree ClassifierPinterest · OAPinterest interview questions
  • Maximum Signal Walk in a Server TreeTower Research Capital · OA
  • Ordered-Pair Checksum SumBirla Pivot · OA
  • Count Pairs with K Divisible Values in the IntervalChubb · OAChubb interview questions
  • Predict Taxi Driver ClassesBoston Consulting Group · OABoston Consulting Group interview questions
  • Balance a Chemical EquationMicrosoft · OAMicrosoft interview questions
  • Arithmetic Triplets After QueriesCapital One · OACapital One interview questions
  • Reaching PointsVirtu Financial · OAVirtu Financial interview questions
All Fortinet interview questionsSee Fortinet hiring insights
Saved
class Solution {
    public int computeChecksumAggregation(int n) {
      // write your code here
    }

}
Checking account…