今天分享的是IBM的一道OA,据说这个OA很容易获得,但是希望同学们也要认真对待。
Question 1
Problem Description: There is an infinite array of integers numbered consecutively from 0. At each step, a pointer can move from index iii to index i+ji + ji+j, or remain where it is. The value of iii begins at 0. The value of jjj begins at 1 and at each step, jjj increments by 1. There is one known index that must be avoided. Determine the highest index that can be reached in a given number of steps.
Parameters:
- steps: the number of steps to take
- badIndex: the bad index to avoid
Example:
Given:
- steps = 4
- badElement = 6
The pointer is limited to 4 steps and should avoid the bad item 6.
Scenarios:
- Scenario 1:
- Step 1: starts at 1. Move 1 unit to index 0 + 1 = 1 (j = 2).
- Step 2: move 2 units to index 1 + 2 = 3 (j = 3).
- Step 3: do not move. (j = 4).
- Step 4: move 4 units to item 3 + 4 = 7 (j = 5).
- Scenario 2:
- Step 1: remain at index 0. (j = 2).
- Step 2: move 2 units to index 0 + 2 = 2 (j = 3).
- Step 3: move 3 units to index 2 + 3 = 5 (j = 4).
- Step 4: move 4 units to index 5 + 4 = 9 (j = 5).
The maximum index that can be reached is 9.
Function Description:
Complete the function maxIndex
in the editor below.
maxIndex
has the following parameters:
int steps
: the number steps to takeint badIndex
: the bad index
Returns:
- int: the maximum index that can be reached from index 0
Constraints:
- 1≤steps≤20001 \leq \text{steps} \leq 20001≤steps≤2000
- 1≤badIndex≤4×1061 \leq \text{badIndex} \leq 4 \times 10^61≤badIndex≤4×106
Input Format for Custom Testing:
The input format for your function will be as follows:
- The number of steps you can take.
- The bad index that needs to be avoided.
Sample Cases:
- Sample Case 0:
- Input:
steps = 2, badIndex = 2
- Output:
3
- Explanation: Move 2 steps and avoid index number 2. At step 1, move 1 unit to step 0 + 1 = 1. At step 2, move 2 units to step 1 + 2 = 3. The maximum index that can be reached is 3.
- Input:
- Sample Case 1:
- Input:
steps = 2, badIndex = 1
- Output:
2
- Explanation: Move 2 steps and avoid index number 1. At step 1, remain at index 0. At step 2, move 2 units to index 0 + 2 = 2. The maximum index that can be reached is 2.
- Input:
- Sample Case 2:
- Input:
steps = 3, badIndex = 3
- Output:
5
- Explanation: Move 3 steps and avoid index number 3. At step 1, move 1 unit to index 0 + 1 = 1. At step 2, remain at index 1. At step 3, move 3 units to index 1 + 3 = 4. Another scenario could reach index 5 by remaining at 0 then moving to index 2 and finally to index 5.
- Input:
Question 2
Problem Description: A coding platform maintains all the participating hackers' data in the HACKER
table. You need to write a query to print the names of all the hackers who have earned more than 100 hackos in less than 10 months. The results should be printed in the ascending order of their ID.
Input Format: The HACKER
table contains the following columns:
- ID: An integer, the hacker's ID in the range [1, 1000]. This is the primary key.
- NAME: A string containing between 1 and 100 characters.
- MONTHS: An integer representing the total number of months the hacker has been programming.
- HACKOS: An integer indicating the total number of points the hacker gained per month.
Output Format: The output should list only the hacker's name, one per line.
Sample Input:
ID | NAME | MONTHS | HACKOS |
---|---|---|---|
1 | Frances White | 5 | 20 |
Expected Output:
- No output since Frances White does not meet the criteria of earning more than 100 hackos in less than 10 months.
如果您也有OA代写的需求,请联系我们,我们服务至上,励志做北美面试支持机构第一品牌。 CSOAHELP