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
Be the first one to answer
Add answer anonymously...
Facebook Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter