
Asked in Facebook
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!
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
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for Facebook Software Developer Intern
C++ Interview Questions and Answers
300 Questions
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

