FastPrepCyclic Shift to Strictly Descending Array

Cyclic Shift to Strictly Descending Array

Capital One logoCapital One● EasyFULLTIMEOA
Learn

Problem statement

Complete the function below. The function receives the full standard input as a single string and must return the exact standard output value for the described problem.

Original prompt

Problem Given an integer array nums of length n and an integer t (0 <= t < n). Define one cyclic shift as moving the last t elements of the array to the front (i.e., a right rotation by t).

Determine whether applying this shift once makes the array strictly descending.

Return true/false.

Note: The original description is slightly ambiguous about whether t is given or you may choose t. This version assumes t is given and you check the result after one shift.

Input

Integer array nums Integer t

Output

true or false Constraints (suggested) 1 <= n <= 2e5 0 <= t < n -1e9 <= nums[i] <= 1e9

Examples nums=[3,2,1], t=0 → true nums=[1,3,2], t=1 → false nums=[2,1,3], t=2 → false nums=[4,3,2,1], t=1 → false nums=[2,1], t=1 → false

Function

solveOneCyclicShiftStrictlyDescending(input: String) → String

Complete solveOneCyclicShiftStrictlyDescending. It has one parameter, String input, containing the full stdin payload. Return the exact stdout value as a string, either "true" or "false".

Examples

Example 1

input = "3\n3 2 1\n0"return = "true"

The returned string must match the expected standard output for the sample input.

Constraints

  • Use the limits and requirements stated in the prompt.

More Capital One problems

See Capital One hiring insights
public String solveOneCyclicShiftStrictlyDescending(String input) {
    // write your code here
}
input"3\n3 2 1\n0"
expected"true"
Checking account…