
You are given three independent coding tasks.
Given a string s (ASCII letters), if both the first and last characters are vowels (a,e,i,o,u case-insensitive), return a new string where:
Otherwise, return s unchanged.
Examples
"apple"
→ first=
a
(vowel), last=
e
(vowel) ⇒ reverse middle
"ppl"
→
"alppe"
"code"
→ first=
c
not vowel ⇒
"code"
Edge cases
len(s) <= 2
, there is no “middle”; return
s
.
You are given an m x n grid of characters. Each cell contains either:
'0'..'9'
, or
'+'
or
'-'
.
You start at the top-left cell (0,0) and must reach the bottom-right cell (m-1,n-1) by moving only:
As you traverse cells, you concatenate their characters to form an arithmetic expression, which is evaluated left-to-right (i.e., no operator precedence beyond sequential evaluation).
Validity assumption: Any path considered must form a valid expression of the form digit (op digit)* (alternating digit/operator), and it must start and end with a digit.
Direction-change constraint: Along the path, you are allowed to change direction at most once (i.e., the move sequence is either all rights then all downs, or all downs then all rights).
Goal: Return the maximum value achievable among all valid paths satisfying the movement constraint.
Given an integer array nums, count how many contiguous subarrays have strictly alternating parity (odd/even/odd/even... or even/odd/even/odd...).
A subarray of length 1 always counts.
Example
nums = [1, 2, 4]
[1]
,
[2]
,
[4]
,
[1,2]
, but
[2,4]
is not alternating (even, even), and
[1,2,4]
is not alternating.
4
Performance requirement: Design an algorithm faster than brute force (e.g., O(n)).