Round 1
Questions:
Problem 1: Valid String Check
Difficulty: Easy
Description: Given a string, check if it is valid or not. A valid string must:
- Be divisible by 3 (interpreted as the numeric value of the string is divisible by 3).
- Contain the digit '7' at least twice.
Testcases:
Valid strings: 771, 777, 123777
Invalid strings: 12345, 71, 171, 70
Candidate's Approach
I implemented a simple approach, doing as asked in the description for each string.
Interviewer's Feedback
No feedback provided.
Problem 2: Command Frequency Counter
Difficulty: Easy
Description:
You are given an array of commands. There are only three possible commands: cmd1
, cmd2
, and cmd3
. Your task is to return an array of size 3 that contains the frequency of each command in the input array, in the order [frequency of cmd1, frequency of cmd2, frequency of cmd3].
Also, any element in the form of !
Input:
[cmd1, cmd2, cmd3, !1, !2, cmd3, cmd1]
Output:
[3, 2, 2]
At index 4 (!1), the command is the same as the command at index 1 (cmd1).
At index 5 (!2), the command is the same as the command at index 2 (cmd2).
Candidate's Approach
I solved it in one pass with no extra space.
Interviewer's Feedback
No feedback provided.
Problem 3: Regional Maximum Finder
Difficulty: Medium or maybe Hard
Description: You are given a 2D array. Your task is to find the regional maxima in the array and return a 2D array of size (X * 2) where each row contains the position [i, j] of a regional maximum.
Definition of Regional Maximum: A cell (i, j) is considered a regional maximum if:
- array[i][j] != 0
- array[i][j] is the maximum value within its region.
Definition of Region: For a cell (i, j) with value cell:
- The region is defined as the rectangular area (
i - cell
toi + cell
) * (j - cell
toj + cell
). - Exclude the corner cells from above:
(i - cell, j - cell)
,(i - cell, j + cell)
,(i + cell, j - cell)
and(i + cell, j + cell)
. - If the calculated region goes out of bounds, ignore those out-of-bound cells.
Input:
[ [3, 0, 1], [2, 0, 0], [0, 0, 0], ]
Output:
[[0, 0], [0, 2]]
The dimensions of the array were relatively small, like 100 * 100, so performance constraints were manageable.
Candidate's Approach
I solved it with worse time-complexity (4 nested loops) same as what comes to mind at first glance, not sure how to optimise. Would love to know your thoughts.
Interviewer's Feedback
No feedback provided.
Problem 4: Sliding Window Problem
Difficulty: Leetcode says Hard
The fourth problem was based on this LeetCode question:
Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit
The problem statement was phrased differently, but the solution required implementing the exact same logic as this LeetCode problem.
Candidate's Approach
I gave the most optimal solution; you can check out the discussion tab of the problem.
Interviewer's Feedback
No feedback provided.