This multi-part prompt evaluates proficiency in core programming competencies: string parsing and character classification, simulation/greedy processing of linear movement and arrays, matrix manipulation including row/column operations and rotations, and undirected graph path reconstruction.
You have 4 independent coding tasks.
Given a string s consisting of ASCII letters (and possibly other characters), count:
U
= number of uppercase letters
'A'..'Z'
L
= number of lowercase letters
'a'..'z'
Return the absolute difference |U - L|.
Input: string s
Output: integer
You travel along a 1D line from position 0 to position target > 0.
There are scooters located at positions given by an array scooters (not necessarily sorted). Each scooter can be ridden for up to 10 distance units and then becomes unusable.
Rules of movement:
pos = 0
.
>= pos
and
<= target
, you
walk
to the closest scooter on your right (i.e., the smallest scooter position
p
such that
p >= pos
).
p
, you
ride
it forward for
min(10, target - p)
distance units, ending at
pos = p + min(10, target - p)
.
target
or there is no scooter at or ahead of your current position before
target
. If no such scooter exists, you walk the remaining distance to
target
.
Return the total distance traveled while riding scooters (do not include walking distance).
Input: integer target, integer array scooters
Output: integer total ridden distance
Given an m x n matrix A and a list of operations, apply them in order and return the final matrix.
Supported operations:
SWAP_ROW r1 r2
: swap row
r1
and row
r2
SWAP_COL c1 c2
: swap column
c1
and column
c2
REVERSE_ROW r
: reverse the elements within row
r
(e.g.,
[1,2,3] -> [3,2,1]
)
REVERSE_COL c
: reverse the elements within column
c
ROTATE_CW
: rotate the entire matrix 90 degrees clockwise (dimensions become
n x m
)
Assume indices are 0-based and all operations are valid.
Input: matrix A, list of operations (with parameters)
Output: final matrix after all operations
You forgot the exact travel order, but you have n-1 photos. Each photo records two consecutive locations you visited, but the order within a photo is unknown.
Example: [[1,2],[3,2],[4,3]] corresponds to the path [1,2,3,4] (or the reverse [4,3,2,1]).
Given an array photos of length n-1, where each element is a pair [a, b] representing an undirected adjacency between consecutive locations, reconstruct and return the full path as an array of length n.
You may return the path in either direction.
Input: array photos of pairs
Output: array path listing all locations in order
Assumptions: The underlying graph formed by the pairs is guaranteed to be a simple path (i.e., exactly two endpoints with degree 1, all others degree 2).