Skip to content
Onsite

Subsequence With Odd Ends

EasyP3Coding

Given an array nums of positive integers, decide whether some subsequence with at least two elements starts with an odd number and ends with an odd number.

A subsequence keeps the original order and may skip elements; the first and last chosen elements must be at different positions.

Example 1

Input
nums = [2,3,4,5]
Output
true
Why
Pick 3 and 5; the subsequence [3, 5] starts and ends with an odd number.

Example 2

Input
nums = [1]
Output
false

Example 3

Input
nums = []
Output
false

Constraints

  • 0 <= nums.length <= 10^5
  • 1 <= nums[i] <= 10^9

Hints

Run checks the 3 visible tests, Submit all 9.