You are given four independent coding questions.
Q1) Best value-for-money item
You are given two arrays of equal length prices and ratings (each ratings[i] is an integer from 1 to 5).
Define the value-for-money score of item i as:
-
score(i) = ratings[i] / prices[i]
Return the index of the item with the maximum score. If multiple items tie for the maximum score, return the smallest index among them.
Assume prices[i] > 0. Use 0-based indices.
Q2) Minutes since the most recent departed bus
You are given:
-
departure_times
: an array of strings, each in 24-hour format
"HH:MM"
, representing bus departure times within the same day (e.g.,
["11:20", "15:00"]
).
-
current_time
: a string
"HH:MM"
representing the current time within the same day.
You must find the departure time that is the latest time strictly earlier than current_time (i.e., if a bus departs at exactly current_time, it is not considered “already departed”).
Return how many minutes have passed since that departure:
-
current_time - last_departure_time
in minutes
If there is no departure time strictly earlier than current_time, return -1.
Q3) Max value expression along a straight path in a grid
You are given a 2D character matrix puzzle whose cells contain only:
-
a single digit character
'0'
–
'9'
, or
-
'+'
, or
-
'-'
You must choose a path that forms a valid arithmetic expression and return the maximum value achievable.
Rules:
-
You may start at
any cell containing a digit
.
-
From the start, you must move in a
single straight direction only
: either
-
move
right
any number of steps (possibly stopping early), or
-
move
down
any number of steps (possibly stopping early).
You
cannot change direction
once chosen.
-
Reading the characters along the visited cells in order yields an expression that must be valid:
-
It must
start with a digit
.
-
Digits and operators must
alternate
(no two consecutive digits, no two consecutive operators).
-
It must
end with a digit
.
-
Evaluate the expression using standard integer arithmetic with only
+
and
-
(equivalently, left-to-right evaluation since precedence is the same).
Return the maximum evaluated result among all valid paths. (Assume at least one valid expression exists unless you decide to return something like negative infinity / null if none exists.)
Q4) Dynamic pair-sum queries with updates
You are given two integer arrays:
You are also given a list of operations operations, each operation is one of:
-
Type 0 (update)
:
[0, index, val]
meaning set
secondary[index] = val
.
-
Type 1 (query)
:
[1, targetSum]
meaning count the number of pairs
(i, j)
such that:
-
0 <= i < len(primary)
,
0 <= j < len(secondary)
, and
-
primary[i] + secondary[j] == targetSum
For each Type 1 operation, output its count. Return all Type 1 results in order as an array.
Constraints are not specified; your solution should handle many operations efficiently (faster than recomputing all pairs on every query).