Implement array rotations and CSV keyword search
Warner Bros DiscoverySoftware Engineer · Technical ScreenLast updated
This question evaluates array manipulation and string parsing competencies, focusing on rotating arrays via modular index arithmetic and locating substring occurrences within a simple CSV while mapping each match to row, column, and character position.
Problem A — Rotate an array left/right by k
You are given an integer array nums of length n and an integer k.
- Implement
rotateLeft(nums, k)that returns the array after rotating it left bykpositions. - Implement
rotateRight(nums, k)that returns the array after rotating it right bykpositions.
Notes / Constraints
kcan be larger thann; treatkask % n.- Handle edge cases like
n = 0orn = 1. - Clarify in your solution whether you modify in-place or return a new array.
Example
nums = [1,2,3,4,5],k = 2- left rotate →
[3,4,5,1,2] - right rotate →
[4,5,1,2,3]
Problem B — Find keyword occurrences in a CSV text
You are given a CSV document as a single string csvText.
- Rows are separated by newline characters
\n. - Columns are separated by commas
,. - Assume fields do not contain escaped commas or quoted strings (i.e., simple CSV).
Task
Given csvText and a keyword key, return all occurrences of key in the document.
For each occurrence, return:
row: the 0-based row numbercol: the 0-based column numberpos: the 0-based character index within that cell where the match begins
Return results in row-major order.
Variant
Extend the function to accept multiple keywords keys[] and return occurrences for any of them (you may also include which keyword matched).
Example
csvText = "foo,bar\nxxfood,barfoo", key = "foo"
- Row 0, Col 0, Pos 0 ("foo")
- Row 1, Col 0, Pos 2 ("xxfood")
- Row 1, Col 1, Pos 3 ("barfoo")
(Exact output format is up to you; it just needs to include row/col/pos.)
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.