Simple File Parser
Function Name: parseLogFile
Description
In this challenge, you are required to write a function named `parseLogFile` that processes a simple log file. The log file is represented as a single string, with each entry separated by a newline character. Each entry in the log starts with a timestamp (in the format 'YYYY-MM-DD HH:MM:SS'), followed by a space, then a log level (either 'INFO', 'WARNING', or 'ERROR'), another space, and finally the log message. Your function should return the number of log messages for each log level.
Requirements
- The function `parseLogFile` must accept a single parameter: a string representing the contents of the log file.
- The function must return an object/dictionary with the keys being the log levels ('INFO', 'WARNING', and 'ERROR') and the values being the counts of each respective log level's occurrence in the log file.
- Assume that the log file string is well-formed and no invalid entries are present.
- Newline characters should be considered as the entry separator, and can be assumed to be the platform's standard newline format.
- The log message itself will not contain any newline characters.
- The parsing should be case-sensitive, with log levels matching exactly 'INFO', 'WARNING', and 'ERROR'.
Examples
Given the log file content as a string:
'2023-03-15 12:45:02 INFO User logged in\n2023-03-15 12:46:14 WARNING Disk space reaching limit\n2023-03-15 12:47:30 ERROR Network unavailable'
Calling parseLogFile on this string should return the following object/dictionary:
{ 'INFO': 1, 'WARNING': 1, 'ERROR': 1 }Links
Two-Sum Problem
Mon Nov 25 2024
Write a function that takes an array of integers and a target integer as its parameters. The function should find two distinct elements in the array that sum up to the given target. The function should return indices of the two numbers such that they add up to the target, where the index of the first number is less than the index of the second number. If no such numbers exist, the function should return null or an equivalent value in your chosen language.
Min Stack Implementation
Wed Nov 27 2024
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.Implement the 'MinStack' class:- 'MinStack()' initializes the stack object.- 'void push(int val)' pushes the element val onto the stack.- 'void pop()' removes the element on the top of the stack.- 'int top()' gets the top element of the stack.- 'int getMin()' retrieves the minimum element in the stack.* You must implement a solution with O(1) time complexity for each function.