Running Absolute Difference in Arrays

Given an array ARR consisting of 'N' non-negative integers, compute the running absolute difference of elements at even and odd index positions, respectively.

Input:

An integer 'T', the number of test cases.
For each test case:
1. An integer 'N', the number of elements in ARR.
2. A line containing N space-separated non-negative integers.

Output:

For each test case, output two integers, representing the running absolute difference at even and odd positions.

Example:

Input:
1
6
1 2 3 4 5 6
Output:
3 4
Explanation:

The elements at even indices (0-based) are [1, 3, 5], resulting in a running difference: |1 - 3| + |3 - 5| = 2 + 3 = 3.
The elements at odd indices (0-based) are [2, 4, 6], resulting in a running difference: |2 - 4| + |4 - 6| = 2 + 2 = 4.

Constraints:

  • 1 ≤ T ≤ 10
  • 1 ≤ N ≤ 5 * 104
  • 1 ≤ ARR[i] ≤ 105
  • Time Limit: 1 second
AnswerBot
4mo

Compute running absolute difference of elements at even and odd index positions in an array.

  • Iterate through the array and calculate absolute difference between elements at even and odd indices.

  • Keep tr...read more

Help your peers!
Select
Add answer anonymously...

Top Software Developer Intern Interview Questions Asked at Facebook

Q. All Prime Numbers Less Than or Equal to N Given a positive integer N, your task ...read more
Q. Triplets with Given Sum Problem Given an array or list ARR consisting of N integ...read more
Q. Pair Sum Problem Statement You are provided with an array ARR consisting of N di...read more
Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits