← All questions
MediumCoding

Sum of Distances

Asked atSprinklr
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
  1. 01Clarify whether distance means graph distance, array-index distance, or coordinate distance.
  2. 02For equal-value index distances, group indices by value.
  3. 03Process each sorted group with running prefix sums.
  4. 04For coordinate pairs, sort and sum left and right contributions.

Reference answer

Then expect these follow-ups

  • Why are groups already sorted by index?

    Tests: observations

  • How does the formula change for coordinates?

    Tests: generalization

Hiring now

Sprinklr has 53 open roles right now

landed applies to roles like these for you, on each company’s own site, with answers written for the role.

Get 5x interviews10 free auto-applies. No card.
  • Senior Sales Development Representative (Large Enterprise), ASEAN and North Asia

    Singapore

  • Program Manager Lead - Community

    South Korea - Seoul

  • Sr. Customer Success Manager

    Japan - Tokyo

Or practice this question first

Next question