最近的OA难度越来越低了,快一起来看看吧
1.Code Question
Amazon Web Services is experimenting with optimizing search queries based on the location of the first unique character in a search. You have been asked to help test the query your team has created to ensure it works as designed. A unique character is one which appears only once in a string. Given a string consisting of lowercase English letters only, return the index of the first occurrence of a unique character in the string using 1-based indexing. If the string does not contain any unique character, return -1.
Example:
s=”statistics”
- The unique characters are [a,c] among which ‘a’ occurs first. Using 1-based indexing, it is at index 3.
Function Description:
Complete the function findFirstUnique in the editor below. findFirstUnique has the following parameter(s):
string s: a string
Returns
int: either the 1-based index or -1.
2.Code Question 2
A financial analyst for Amazon Web Services (AWS) is responsible for a portfolio of profitable stocks represented in an array. Each item in the array represents the yearly profit of a corresponding stock. The Amazonian gathers all distinct pairs of stocks that reached the target profit. Distinct pairs are pairs that differ in at least one element. Given the array of profits, find the number of distinct pairs of stocks where the sum of each pair’s profits is exactly equal to the target profit.
Example:
stocksProfit = [5, 7, 9, 13, 11, 6, 6, 3, 3]
target = 12 profit’s target
- There are 4 pairs of stocks that have the sum of their profits equal to the target 12. Note that because there are two instances of 3 in stocksProfit, there are two pairs matching (9, 3): stocksProfits indices 2 and 7, and indices 2 and 8, but only one can be included.
- There are 3 distinct pairs of stocks: (5, 7), (3, 9), and (6, 6), and the return value is 3.
Function Description:
Complete the function getDistinctPairs in the editor below.
getDistinctPairs has the following parameter(s):
- int stocksProfit[n]: an array of integers representing the stocks profits
- target: an integer representing the yearly target profit
Returns
- int: the total number of pairs determined
Constraints:
- 1 ≤ n ≤ 5 × 10^5
- 0 ≤ stocksProfit[i] ≤ 10^9
- 0 ≤ target ≤ 5 × 10^9
我们还提供OA与VO的咨询与支持服务,如果有需要,请联系我们:
chen@csoahelp.com
We also provide consultation and support services for OA and VO. If needed, please feel free to contact us:
chen@csoahelp.com