PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • medium
  • Warner Bros Discovery
  • Coding & Algorithms
  • Software Engineer

Implement array rotations and CSV keyword search

Company: Warner Bros Discovery

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem A — Rotate an array left/right by *k* You are given an integer array `nums` of length `n` and an integer `k`. 1. Implement `rotateLeft(nums, k)` that returns the array after rotating it left by `k` positions. 2. Implement `rotateRight(nums, k)` that returns the array after rotating it right by `k` positions. ### Notes / Constraints - `k` can be larger than `n`; treat `k` as `k % n`. - Handle edge cases like `n = 0` or `n = 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 number - `col`: the 0-based column number - `pos`: 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.)

Quick Answer: 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.

Rotate an Array Left or Right by k

You are given an integer array `nums` of length `n`, an integer `k`, and a string `direction` that is either `"left"` or `"right"`. Return a NEW array that is `nums` rotated by `k` positions in the given direction. Rules: - `k` may be larger than `n`; treat it as `k % n`. - Handle edge cases: `n = 0` returns an empty array, `n = 1` returns the array unchanged. - A left rotation by `k` moves the first `k` elements to the end; a right rotation by `k` moves the last `k` elements to the front. Example: `nums = [1,2,3,4,5]`, `k = 2` - direction `"left"` -> `[3,4,5,1,2]` - direction `"right"` -> `[4,5,1,2,3]`

Constraints

  • 0 <= n <= 10^5
  • 0 <= k <= 10^9
  • direction is either "left" or "right"
  • -10^9 <= nums[i] <= 10^9

Examples

Input: ([1, 2, 3, 4, 5], 2, 'left')

Expected Output: [3, 4, 5, 1, 2]

Explanation: Move the first 2 elements [1,2] to the end.

Input: ([1, 2, 3, 4, 5], 2, 'right')

Expected Output: [4, 5, 1, 2, 3]

Explanation: Move the last 2 elements [4,5] to the front.

Input: ([1, 2, 3, 4, 5], 7, 'left')

Expected Output: [3, 4, 5, 1, 2]

Explanation: k > n: 7 % 5 = 2, so this matches a left rotation by 2.

Input: ([1, 2, 3, 4, 5], 7, 'right')

Expected Output: [4, 5, 1, 2, 3]

Explanation: k > n: 7 % 5 = 2, so this matches a right rotation by 2.

Input: ([], 3, 'left')

Expected Output: []

Explanation: Empty array stays empty regardless of k.

Input: ([42], 5, 'right')

Expected Output: [42]

Explanation: Single element: k % 1 = 0, array unchanged.

Input: ([1, 2, 3, 4, 5], 5, 'left')

Expected Output: [1, 2, 3, 4, 5]

Explanation: k % n = 0: a full rotation returns the original order.

Input: ([-1, -2, 0, 3], 1, 'right')

Expected Output: [3, -1, -2, 0]

Explanation: Negatives handled like any value; last element moves to front.

Hints

  1. Reduce k modulo n first so that rotations larger than the array length wrap correctly.
  2. A left rotation by k is a slice split: nums[k:] + nums[:k].
  3. A right rotation by k is equivalent to a left rotation by n - k: nums[n-k:] + nums[:n-k].
  4. Guard the n == 0 case before computing k % n to avoid a division-by-zero.

Find Keyword Occurrences in Simple CSV

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 `,`. - Fields are simple: no quoted strings and no escaped commas. Return every occurrence of `key` as a triple `[row, col, pos]`, where: - `row` is the 0-based row index, - `col` is the 0-based column index within that row, - `pos` is the 0-based character index inside that cell where the match begins. Matches may overlap (e.g. `key = "aa"` in `"aaa"` matches at positions 0 and 1). Return results in row-major order (rows in order, then columns in order, then by position within a cell). If `key` is empty, return an empty list. Example: `csvText = "foo,bar\nxxfood,barfoo"`, `key = "foo"` -> `[[0,0,0], [1,0,2], [1,1,3]]`

Constraints

  • 0 <= len(csvText) <= 10^5
  • 0 <= len(key) <= 10^3
  • csvText uses '\n' as the row separator and ',' as the column separator
  • Fields contain no quoted strings or escaped commas
  • Matches may overlap

Examples

Input: ("foo,bar\nxxfood,barfoo", "foo")

Expected Output: [[0, 0, 0], [1, 0, 2], [1, 1, 3]]

Explanation: "foo" at row 0 col 0 pos 0; inside "xxfood" at row 1 col 0 pos 2; inside "barfoo" at row 1 col 1 pos 3.

Input: ("abc,abcabc", "abc")

Expected Output: [[0, 0, 0], [0, 1, 0], [0, 1, 3]]

Explanation: Cell 0 has one match; cell 1 ("abcabc") has two non-overlapping matches at pos 0 and 3.

Input: ("hello,world", "xyz")

Expected Output: []

Explanation: Keyword not present anywhere.

Input: ("", "foo")

Expected Output: []

Explanation: The only cell is the empty string, which contains no match.

Input: ("aaa", "aa")

Expected Output: [[0, 0, 0], [0, 0, 1]]

Explanation: Overlapping matches: "aa" begins at pos 0 and pos 1 within "aaa".

Input: ("a,b,c\nd,e,f", "e")

Expected Output: [[1, 1, 0]]

Explanation: "e" appears only in row 1, column 1, at pos 0.

Input: ("foo,bar", "")

Expected Output: []

Explanation: Empty key returns no matches by definition.

Input: ("x,,xx", "x")

Expected Output: [[0, 0, 0], [0, 2, 0], [0, 2, 1]]

Explanation: Empty middle cell yields nothing; "xx" yields two matches at pos 0 and 1.

Hints

  1. Split csvText on '\n' to get rows, then split each row on ',' to get cells; the indices of these splits are your row and col.
  2. Within a cell, repeatedly call find(key, start) and advance start to idx + 1 (not idx + len(key)) so overlapping matches are counted.
  3. Stop the inner loop when find returns -1.
  4. Treat an empty key as a special case and return no matches to avoid an infinite loop.
Last updated: Jun 26, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.