HTTP Log Queries
Problem statement
You are given HTTP request logs. Each row is [ip, verb, status, responseTime, size, requestTime]. Every field is a string. The last field is the request timestamp in seconds. Rows may arrive in any order, and equal or duplicate rows are separate requests.
Process each query independently over the complete, unchanged log list. A query is [startTime, endTime, statusFilter, ipFilter, mode]. Match requests whose timestamp is in the inclusive range [startTime, endTime]. A filter matches its exact string value, or matches every value when it is *.
Query modes
- LIST: return the matching zero-based log indices as decimal strings, in original input order.
- STATUS: count matching requests by status. A group key is the status string.
- IP: count matching requests by IP. A group key is the IP string.
- IP_STATUS: count matching requests by the pair of IP and status. A group key is ip + a comma + status.
For each counting mode, return one string key=count per group, with keys in lexicographic string order. Count every matching request once. Do not return groups with zero matches. Return one result row per query, in query order. A query with no matches produces an empty row.
The verb, responseTime and size fields are retained as request metadata; they do not affect these queries.
Function
queryHttpLogs(logs: String[][], queries: String[][]) → String[][]Examples
Example 1
logs = [["10.0.0.1","GET","200","12","100","20"],["10.0.0.2","POST","500","30","50","10"],["10.0.0.1","GET","200","8","70","20"],["10.0.0.2","GET","200","15","80","30"]]queries = [["10","20","*","*","LIST"],["0","30","200","*","IP"],["20","20","*","10.0.0.1","STATUS"],["0","30","*","*","IP_STATUS"]]return = [["0","1","2"],["10.0.0.1=2","10.0.0.2=1"],["200=2"],["10.0.0.1,200=2","10.0.0.2,200=1","10.0.0.2,500=1"]]The first query includes indices 0, 1 and 2, in input order. Filtering for status 200 leaves two requests from 10.0.0.1 and one from 10.0.0.2. At timestamp 20, IP 10.0.0.1 has two status-200 requests. The last query forms three IP/status groups with counts 2, 1 and 1.
Example 2
logs = [["1.1.1.1","HEAD","404","0","0","0"]]queries = [["1","2","*","*","LIST"],["0","0","200","*","STATUS"]]return = [[],[]]The first query excludes timestamp 0. The second includes that timestamp but requires status 200, while the only request has status 404. Both result rows are empty.
Example 3
logs = []queries = [["0","0","*","*","LIST"],["0","0","*","*","IP"]]return = [[],[]]There are no requests to match. Each query still contributes one empty result row.
Constraints
- 0 <= logs.length <= 2000.
- 0 <= queries.length <= 500.
- Every log row has exactly 6 fields. Every query row has exactly 5 fields.
- Every field is a nonempty string of at most 32 characters.
- IP values are dotted-decimal IPv4 addresses without leading zeros. A verb contains only uppercase ASCII letters.
- Numeric fields are canonical decimal integer strings without leading zeros except 0. Status values range from 100 to 599. responseTime, size, requestTime, startTime and endTime range from 0 to 10^9.
- Each query satisfies startTime <= endTime. Its statusFilter and ipFilter are * or valid exact values of their respective fields. Its mode is LIST, STATUS, IP or IP_STATUS.
- The total number of strings returned across all query results is at most 5000.