FastPrepServer Log Summary and Minute Anomalies
Problems/Server Log Summary and Minute Anomalies

Server Log Summary and Minute Anomalies

NinjaTrader logoNinjaTrader● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report establishes the task identity and central capability. This practice contract supplies only the portable interface, deterministic boundary rules, and output serialization needed for consistent execution.

Analyze decoded server-log candidates. Each valid row is [timestampMillis, level, latencyMillis, statusCode]. Skip any row whose field count is not four or whose timestamp, latency, or status is not an integer.

Return output lines in this order:

  1. LEVEL name=count for present levels in lexicographic order.
  2. AVG_LATENCY=x.xx over all valid rows.
  3. STATUS code=count for present codes in numeric order.
  4. For every minute bucket in numeric order whose percentage of status codes at least 500 is at least errorRatePercent or whose average latency is at least latencyThreshold: ANOMALY minute=m errorRate=x.xx avgLatency=y.yy.

Return an empty array when no row is valid.

Function

analyzeLogs(records: String[][], latencyThreshold: int, errorRatePercent: int) → String[]

Examples

Example 1

records = [["0","INFO","100","200"],["30000","ERROR","300","500"]]latencyThreshold = 250errorRatePercent = 50return = ["LEVEL ERROR=1","LEVEL INFO=1","AVG_LATENCY=200.00","STATUS 200=1","STATUS 500=1","ANOMALY minute=0 errorRate=50.00 avgLatency=200.00"]

The minute reaches the error-rate threshold exactly.

Example 2

records = [["bad","INFO","10","200"],["1","INFO"]]latencyThreshold = 100errorRatePercent = 50return = []

Both rows are malformed and skipped.

Constraints

  • 0 <= records.length <= 10^5.
  • Valid timestamps and latencies are nonnegative; status codes are positive.
  • Thresholds are nonnegative.
See NinjaTrader hiring insights
Saved
class Solution {
    public String[] analyzeLogs(String[][] records, int latencyThreshold, int errorRatePercent) {
      // write your code here
    }
}
Checking account…