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
3d
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 Facebook Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Stay ahead in your career. Get AmbitionBox app
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
Get AmbitionBox app