Implement array rotations and CSV keyword search
Problem 1: Array Rotations
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.
Constraints & Notes
kcan be larger thann; treatkask % n.- Handle edge cases such as
n = 0orn = 1. - Clarify in your solution whether you modify the array 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]
- Left rotate →
Problem 2: CSV Keyword Search
You are given a CSV document as a single string csvText and a keyword key.
- 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
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
Results should be returned in row-major order. The exact output format (e.g., list of objects, tuples) is flexible, as long as it includes row, col, and pos.
Variant
Extend the function to accept multiple keywords keys[] and return occurrences for any of them. You may also include which keyword matched in the output.
Example
csvText = "foo,bar\nxxfood,barfoo", key = "foo"
Expected occurrences:
- Row 0, Col 0, Pos 0 ("foo")
- Row 1, Col 0, Pos 2 ("xxfood")
- Row 1, Col 1, Pos 3 ("barfoo")
AI interview prep
Core dilemma
Demonstrating robust algorithmic problem-solving for common data structures (arrays) and string processing (CSV parsing, substring search) under various constraints, emphasizing efficiency and meticulous edge case handling across two distinct problem types.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Implement array rotations and CSV keyword search
Problem 1: Array Rotations
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.
Constraints & Notes
kcan be larger thann; treatkask % n.- Handle edge cases such as
n = 0orn = 1. - Clarify in your solution whether you modify the array 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]
- Left rotate →
Problem 2: CSV Keyword Search
You are given a CSV document as a single string csvText and a keyword key.
- 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
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
Results should be returned in row-major order. The exact output format (e.g., list of objects, tuples) is flexible, as long as it includes row, col, and pos.
Variant
Extend the function to accept multiple keywords keys[] and return occurrences for any of them. You may also include which keyword matched in the output.
Example
csvText = "foo,bar\nxxfood,barfoo", key = "foo"
Expected occurrences:
- Row 0, Col 0, Pos 0 ("foo")
- Row 1, Col 0, Pos 2 ("xxfood")
- Row 1, Col 1, Pos 3 ("barfoo")