Array Challenge (QR Intern)
Updated
Problem statement
You are given an integer array arr.
For each element arr[i]:
- Initialize a counter to
0. - Compare
arr[i]with every elementarr[j]to its left, wherej < i.- If
arr[j] > arr[i], subtract|arr[i] - arr[j]|from the counter. - If
arr[j] < arr[i], add|arr[i] - arr[j]|to the counter. - If the two values are equal, the counter does not change.
- If
Return a new array containing the final counter value for each element.
Function
arrayChallenge(arr: int[]) → int[]Examples
Example 1
arr = [2,4,3]return = [0,2,0]- For
arr[0] = 2, there are no elements to the left, so the counter is0. - For
arr[1] = 4, add|4 - 2| = 2, so the counter is2. - For
arr[2] = 3, first compare with4:0 - |3 - 4| = -1. Then compare with2:-1 + |3 - 2| = 0.
Therefore, return [0, 2, 0].
Constraints
1 <= arr.length <= 10^5.
More Akuna Capital Online Assessment questions
- Delivery Management SystemOA · Seen Nov 2026
- Count Server ReplacementsOA · Seen Nov 2026
- Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximum Remaining Drone PowerOA · Seen Nov 2026
- Rolling MetricsOA · Seen Oct 2026
- Vowel Substring GameOA · Seen Sep 2026
- Competitive ForagingOA · Seen Sep 2026
- Binary CircuitOA · Seen Sep 2026
- Items SortOA · Seen Sep 2026
- Minimize Malware Spread by Removing a NodeOA · Seen Sep 2026
Similar questions at other companies
- Online No-Intercept Linear RegressionTwo Sigma · OATwo Sigma interview questions
- Prefix Scores With the Running MaximumC3.ai · OAC3.ai interview questions
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Diagonal Bounce TraversalAutodesk · OAAutodesk interview questions
- Costliest ChocolateRippling · OARippling interview questions
- Plus Mult ArrayIBM · OAIBM interview questions
- Progressive Tax CalculatorInteractive Brokers · OA
- 2020 Account Balance with Monthly Card FeesDRW · OADRW interview questions
- Range Negation UpdatesJP Morgan Chase · OAJP Morgan Chase interview questions
- Latency Bucket CounterDatadog · OA · PHONE SCREENDatadog interview questions
Akuna Capital interview experiences
- Akuna Capital Quant Trader and QR Interviews: 5 Experiences
- Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
- Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
- Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
- Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)
- Akuna Capital QR Coding Interviews: 17 Experiences (Part 2 of 6)