FastPrepGet Data Dependence Sum
Problems/Get Data Dependence Sum

Get Data Dependence Sum

Amazon logoAmazon● HardINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Data analysts at Amazon are analyzing time-series data. The data of day n depends on the data of day x if there is a positive integer k such that floor(n / k) = x, where floor(z) is the largest integer less than or equal to z.

Given n, return the sum of all distinct days x (0 ≤ x ≤ n) on which the data of day n depends. Each day is counted once, even if several values of k give it.

Function

getDataDependenceSum(n: long) → long

Complete the function getDataDependenceSum in the editor below.

getDataDependenceSum takes the following arguments:

  1. long int n: the day to analyze the data dependency for

Returns long int: the sum of days on which the data is dependent

Input Format For Custom Testing

The first line contains a long integer, n.

Examples

Example 1

n = 13return = 29

floor(13 / k) is 13 for k = 1, 6 for k = 2, 4 for k = 3, 3 for k = 4, 2 for k = 5 and 6, 1 for k = 7 to 13, and 0 for every k >= 14. So the data of day 13 depends on days 0, 1, 2, 3, 4, 6 and 13, and the sum is 0 + 1 + 2 + 3 + 4 + 6 + 13 = 29.

Example 2

n = 1return = 1

floor(1 / 1) = 1 and floor(1 / k) = 0 for every k >= 2. The days are 0 and 1, so the sum is 0 + 1 = 1.

Example 3

n = 5return = 8

floor(5 / k) is 5 for k = 1, 2 for k = 2, 1 for k = 3, 4 and 5, and 0 for every k >= 6. No k gives 3 or 4. The days are 0, 1, 2 and 5, so the sum is 0 + 1 + 2 + 5 = 8.

Constraints

  • 1 <= n <= 10^10

More Amazon interview questions

  • Get Smallest Base SegmentOA · Seen Nov 2026
  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
  • Minimum Grid InconvenienceOA · Seen Nov 2026
  • 3SumPHONE SCREEN · Seen Nov 2026
  • Circular Primes Below a LimitPHONE SCREEN · Seen Nov 2026
  • Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
  • Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
  • Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

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

Amazon interview experiences

  • Amazon SWE OA with AI Coding: 1 Experience
  • Amazon SWE Intern Phone Screen Interview Experience: 1 Experience
  • Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
  • Amazon BIE Intern SQL and Interview Questions: 17 Experiences
  • Amazon Experienced SWE AI-Assisted Debugging OA: 1 Experience
  • Amazon SDE II (L5) Interview Questions: 5 Experiences
See Amazon hiring insights
Saved
class Solution {
    public long getDataDependenceSum(long n) {
      // write your code here
    }

}
Checking account…