Problem · Greedy
Construct Winning Sequence
Learn this problemProblem statement
A challenge in a programming competition requires the construction of a sequence using a specified number of integers within a range. The sequence must be strictly increasing at first and then strictly decreasing. The goal is to maximize the sequence array elements starting from the beginning. For example, [4,5,4,3,2] beats [3,4,5,4,3] because its first element is larger, and [4,5,6,5,4] beats [4,5,4,3,2] because its third element is larger. Given the length of the sequence and the range of integers, return the winning sequence. If it is not possible to construct such a sequence, return -1.
Function
constructSequence(n: int, lo: int, hi: int) → int[]Examples
Example 1
n = 5lo = 1hi = 2return = [-1]It is not possible to construct a sequence that is strictly increasing and then strictly decreasing with the given range of integers.
Example 2
n = 5lo = 4hi = 11return = [10, 11, 10, 9, 8]N/A
Example 3
n = 6lo = 5hi = 10return = [9, 10, 9, 8, 7, 6]N/A
More Salesforce problems
- Minimize Total Input Cost (for LTMS)Seen Jun 2026
- Count Prime StringsONSITE INTERVIEW · Seen Jun 2026
- Final Pod Counts After LogsOA · Seen May 2026
- ATM Queue Exit OrderPHONE SCREEN · Seen May 2026
- Good Ways to Split an ArrayPHONE SCREEN · Seen May 2026
- Generate Seen Binary StringsOA · Seen May 2026
- Update Pod Counts From LogsOA · Seen May 2026
- Minimum Removals to Balance ArrayOA · Seen May 2026