Sign in to track progress, unlock prep layers, and browse your pipeline.Sign in
Solve Five OA Coding Tasks
Coding Tasks
You are presented with five independent coding tasks. Implement a function for each task as described below.
Task 1: Add Drama to Text
- Input: A string
s. - A group is defined as a maximal contiguous sequence of non-whitespace characters.
- Output: A new string where:
- Every period
'.'is replaced with an exclamation mark'!'. - One additional exclamation mark
'!'is appended after each group.
- Every period
- Constraint: Preserve the original whitespace between groups.
- Example:
"hi. there"becomes"hi!! there!".
Task 2: Filter and Reverse Even Numbers
- Input: A list of integers
nums. - Process: Remove all odd numbers from the list.
- Output: The remaining even numbers in reverse order relative to their original appearance.
- Example:
[1, 2, 3, 4, 6, 5]returns[6, 4, 2].
Task 3: Compute a Bounding Rectangle
- Input: A non-empty list of coordinates, where each coordinate is a two-element list
[x, y]. - Output: A four-element list
[minX, minY, width, height], where:minXis the minimum x-coordinate found.minYis the minimum y-coordinate found.widthis calculated asmaxX - minX.heightis calculated asmaxY - minY.
Task 4: Find Incorrect Digit Positions in a Sum
- Input: Three non-negative integers:
num1,num2, andstatedSum. - Process:
- Compute the correct sum:
correctSum = num1 + num2. - Compare
statedSumagainstcorrectSumdigit by digit, starting from the rightmost digit (ones place) and moving left.
- Compute the correct sum:
- Output: A list of zero-based digit indexes where the digits differ. The ones digit has index
0, the tens digit has index1, and so on. - Constraint: If the numbers have different lengths, treat missing higher-order digits as
0during comparison until all digits of both numbers have been consumed. - Example: If
num1 = 99,num2 = 1, andstatedSum = 190, the correct sum is100. The result is[1]because only the tens digit differs.
Task 5: Extract Disallowed URLs for Bot User Agents
- Input:
lines, a list of strings representing the content of a text file, with one line per string. - File Format: The file is similar to a
robots.txtfile and contains sections. A new section begins when a line starts with the exact prefix"User-agent:". - Relevant Section: A section is considered relevant if its user-agent value (after trimming surrounding spaces) either:
- Is exactly
"*", OR - Ends with the exact suffix
"Bot".
- Is exactly
- Extraction: Within every relevant section, collect the URL value found after each line that starts with the exact prefix
"Disallow:". - Section Termination: Stop considering a section when the next
"User-agent:"line is encountered or the end of the file is reached. - Output: All collected URLs, with duplicates removed. The matching is case-sensitive (e.g.,
"/A"and"/a"are distinct URLs). Preserve the order of first occurrence.
AI interview prep
Core dilemma
Demonstrating robust, efficient, and idiomatic solutions across a diverse set of common coding challenges, while managing complexity and edge cases effectively.
Mid-level signals3
Senior signals5
Red flags4
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Solve Five OA Coding Tasks
Coding Tasks
You are presented with five independent coding tasks. Implement a function for each task as described below.
Task 1: Add Drama to Text
- Input: A string
s. - A group is defined as a maximal contiguous sequence of non-whitespace characters.
- Output: A new string where:
- Every period
'.'is replaced with an exclamation mark'!'. - One additional exclamation mark
'!'is appended after each group.
- Every period
- Constraint: Preserve the original whitespace between groups.
- Example:
"hi. there"becomes"hi!! there!".
Task 2: Filter and Reverse Even Numbers
- Input: A list of integers
nums. - Process: Remove all odd numbers from the list.
- Output: The remaining even numbers in reverse order relative to their original appearance.
- Example:
[1, 2, 3, 4, 6, 5]returns[6, 4, 2].
Task 3: Compute a Bounding Rectangle
- Input: A non-empty list of coordinates, where each coordinate is a two-element list
[x, y]. - Output: A four-element list
[minX, minY, width, height], where:minXis the minimum x-coordinate found.minYis the minimum y-coordinate found.widthis calculated asmaxX - minX.heightis calculated asmaxY - minY.
Task 4: Find Incorrect Digit Positions in a Sum
- Input: Three non-negative integers:
num1,num2, andstatedSum. - Process:
- Compute the correct sum:
correctSum = num1 + num2. - Compare
statedSumagainstcorrectSumdigit by digit, starting from the rightmost digit (ones place) and moving left.
- Compute the correct sum:
- Output: A list of zero-based digit indexes where the digits differ. The ones digit has index
0, the tens digit has index1, and so on. - Constraint: If the numbers have different lengths, treat missing higher-order digits as
0during comparison until all digits of both numbers have been consumed. - Example: If
num1 = 99,num2 = 1, andstatedSum = 190, the correct sum is100. The result is[1]because only the tens digit differs.
Task 5: Extract Disallowed URLs for Bot User Agents
- Input:
lines, a list of strings representing the content of a text file, with one line per string. - File Format: The file is similar to a
robots.txtfile and contains sections. A new section begins when a line starts with the exact prefix"User-agent:". - Relevant Section: A section is considered relevant if its user-agent value (after trimming surrounding spaces) either:
- Is exactly
"*", OR - Ends with the exact suffix
"Bot".
- Is exactly
- Extraction: Within every relevant section, collect the URL value found after each line that starts with the exact prefix
"Disallow:". - Section Termination: Stop considering a section when the next
"User-agent:"line is encountered or the end of the file is reached. - Output: All collected URLs, with duplicates removed. The matching is case-sensitive (e.g.,
"/A"and"/a"are distinct URLs). Preserve the order of first occurrence.