[Capital One] Assessment OA 2025 Start – 02 Feb (Generic)

Given an array of integers numbers, your task is to count all numbers that are not equal to numbers[0] or numbers[1], if they exist in the array.

Assume that array indices are 0-based.

Note:

You are not expected to provide the most optimal solution, but a solution with time complexity not worse than O(numbers.length²) will fit within the execution time limit.

Example:

1.

For numbers = [4, 3, 2, 3, 2, 5, 4, 3], the output should be:
solution(numbers) = 3.

Explanation:

  • numbers[0] = 4, numbers[1] = 3
  • There are three elements in numbers that are not equal to 4 or 3:
    • numbers[2] = 2
    • numbers[4] = 2
    • numbers[5] = 5
      Thus, the answer is 3.

2.

For numbers = [3, 3, 1, 1, 3], the output should be:
solution(numbers) = 2.

Explanation:

  • numbers[0] = 3, numbers[1] = 3
  • There are two elements in numbers that are not equal to 3:
    • numbers[2] = 1
    • numbers[3] = 1
      Thus, the answer is 2.

3.

For numbers = [-2], the output should be:
solution(numbers) = 0.

Explanation:

  • numbers[0] = -2, and numbers[1] does not exist.
  • The only requirement is to count numbers different from -2.
  • There are no elements in numbers that are not equal to -2, so the answer is 0.

Input/Output

  • Execution time limit: 3 seconds (Java)
  • Memory limit: 1 GB
  • Input: array of integers numbers
  • Output: integer (count of numbers that are not equal to numbers[0] or numbers[1])

You are given a string text consisting of unique lowercase English words that are divided by spaces.

Your task is to count the absolute difference between the number of vowels (which are 'a', 'e', 'i', 'o', 'u') and the number of consonants in each word. You are to return the array of words in the ascending order of these absolute differences. If the absolute difference is the same, sort the words in alphabetical order.

Note:

You are not expected to provide the most optimal solution, but a solution with time complexity not worse than O(text.length²) will fit within the execution time limit.

Example:

Input:

text = "penelope lives in hawaii"

Output:

solution(text) = ["in", "penelope", "lives", "hawaii"]

Explanation:

  1. Word "penelope"
    • Consonants: p, n, l, p (4)
    • Vowels: e, e, o, e (4)
    • Absolute difference: |4 - 4| = 0
  2. Word "lives"
    • Consonants: l, v, s (3)
    • Vowels: i, e (2)
    • Absolute difference: |3 - 2| = 1
  3. Word "in"
    • Consonants: n (1)
    • Vowels: i (1)
    • Absolute difference: |1 - 1| = 0
  4. Word "hawaii"
    • Consonants: h, w (2)
    • Vowels: a, a, i, i (4)
    • Absolute difference: |2 - 4| = 2

Sorting Order:

  • Words with absolute difference 0: ["in", "penelope"] (sorted alphabetically).
  • Words with absolute difference 1: ["lives"].
  • Words with absolute difference 2: ["hawaii"].

Thus, the final output is:

["in", "penelope", "lives", "hawaii"]

You are given a matrix of integers matrix, your goal is to find all local maximums in it. An element is considered to be a local maximum if it is not zero and there are no greater or equal elements in its region. The region for the element matrix[i][j] is the square with the side length of matrix[i][j] * 2 + 1 and center coordinates at (i, j), excluding the square’s corner elements. The coordinates of the element is 0-based indices of the corresponding row and column.

See an example of the region below. For matrix[2][2] = 2, the size of the square is (matrix[2][2] * 2 + 1) × (matrix[2][2] * 2 + 1), which is 5 × 5, with square’s corner elements being excluded:

Note: if the region is not fully inside the matrix, no special rules are applied. You should only consider the part of the region within the matrix.

Return the 2-dimensional array, where each element is the array of size 2, containing coordinates (row, col) of every local maximum within matrix. The coordinates in the resulting array should be sorted in ascending order by row index or, in case of a tie, by column index.

Note: You are not expected to provide the most optimal solution, but a solution with time complexity not worse than O(matrix.length² * matrix[0].length²) will fit within the execution time limit.


Example

For

matrix = [  
  [3, 0, 0, 0, 0],  
  [0, 0, 1, 0, 0],  
  [0, 0, 2, 0, 0],  
  [0, 0, 0, 0, 0],  
  [0, 3, 0, 0, 3]  
]

the output should be

solution(matrix) = [[0, 0], [2, 2]]

Given an empty array that should contain integers numbers, your task is to process a list of queries on it. Specifically, there are two types of queries:

  • "+x" - add integer x to numbers.
    numbers may contain multiple instances of the same integer.
  • "-x" - remove a single instance of integer x from numbers.

After processing each query, record the number of pairs in numbers with a difference equal to a given diff. The final output should be an array of such values for all queries.

Notes:

  • All numbers in queries are guaranteed to be in the range of -10⁹ to 10⁹, inclusive.
  • It is also guaranteed that for every "-x" query, the specified number x exists in numbers.
  • It is guaranteed that the answer for each query fits into a signed 32-bit integer type.

Example

For

queries = ["+4", "+5", "+2", "-4"]  
diff = 1  

the output should be

solution(queries, diff) = [0, 1, 1, 0]
  1. Process queries[0] = "+4" and add 4 to numbers, resulting in numbers = [4].
    There are no pairs with diff = 1, so append 0 to the output.
  2. Process queries[1] = "+5" and add 5 to numbers, resulting in numbers = [4, 5].
    The numbers 4 and 5 have difference diff = 1, so append 1 to the output.
  3. Process queries[2] = "+2" and add 2 to numbers, resulting in numbers = [4, 5, 2].
    The number of pairs with difference diff = 1 remains the same, so append 1 to the output.
  4. Process queries[3] = "-4" and remove 4 from numbers, resulting in numbers = [5, 2].
    There are no pairs with diff = 1, so append 0 to the output.

我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

Your email address will not be published. Required fields are marked *