Apply Affine Array Transformations
Updated
Problem statement
Transform every element of an integer array values using an ordered list transforms.
For this exercise, assume each transformation is a pair [a,b]. It replaces the current value x with a * x + b. Apply all pairs in their given order to every element, then return the final values in the original array order.
- The same transformation list applies independently to every element.
- An empty transformation list leaves the values unchanged.
- A multiplier of
0resets the current value to that step's offset; later transformations still apply. - An empty input array produces an empty output array.
- Use exact signed 64-bit results. Do not change the input arrays or round, clamp or take a modulus.
Function
transformArray(values: int[], transforms: int[][]) → long[]Examples
Example 1
values = [1,-2,0]transforms = [[2,3],[-1,4]]return = [-1,5,1]The first step gives [5,-1,3]; the second gives [-1,5,1].
Example 2
values = [10,-20]transforms = [[2,1],[0,7],[-2,3]]return = [-11,-11]The middle step replaces every value with 7. The last step therefore returns -11 for both entries.
Example 3
values = [4,4,-1]transforms = []return = [4,4,-1]An empty transformation list preserves every input value and its position.
Constraints
0 <= values.length <= 256.-1000000 <= values[i] <= 1000000.0 <= transforms.length <= 20; every row contains exactly two integers[a,b].-2 <= a <= 2and-1000 <= b <= 1000.- All inputs satisfy these rules. Every intermediate value and result fits a signed 64-bit integer.
More ByteDance Phone Screen questions
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Implement QuicksortPHONE SCREEN · Seen Dec 2026
- Largest Rectangle in HistogramPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Reverse Linked ListPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Count N-Queens PlacementsPHONE SCREEN · Seen Nov 2026
- Matrix EscapePHONE SCREEN · Seen Nov 2026
- Largest Number Below N from Reusable DigitsPHONE SCREEN · Seen Nov 2026
- Log Analyzer: Busiest Service in a Rolling WindowPHONE SCREEN · Seen Nov 2026
- Majority ElementPHONE SCREEN · Seen Nov 2026
- Valid ParenthesesPHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
- Exponential Backoff DelaysWonderful · PHONE SCREEN
- Recover Document Hierarchy from IndentationReducto · PHONE SCREEN
- Latency Bucket CounterDatadog · OA · PHONE SCREENDatadog interview questions
- Mini-Batch Data LoaderOpenAI · PHONE SCREENOpenAI interview questions
- Shuffle a Deck From Random ChoicesGoogle · PHONE SCREENGoogle interview questions
- Sliding Window Attention over a KV CacheNVIDIA · PHONE SCREENNVIDIA interview questions
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Deterministic K-Means AssignmentsLyft · PHONE SCREENLyft interview questions
- Deterministic K-Means AssignmentsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
ByteDance interview experiences
- ByteDance TikTok USDS SWE Intern Interview: 1 Experience
- ByteDance MLE New Grad Interviews: 1 Experience
- ByteDance Security SRE Intern Phone Screens: 1 Experience
- ByteDance USDS New Grad SWE Phone Screen: 1 Experience
- ByteDance New Grad Data Engineer Video Interviews: 1 Experience
- ByteDance Trust & Safety Research Scientist Intern: 1 Experience