Dataset Schema Validator
Learn this problemProblem statement
Implement a validator for a dataset and its schema.
The schema is an array of unique entries in the form key:type. The only supported schema types are str and int.
Each record is an array of entries in the form key:type:value. The first two colons delimit the key and runtime type. Every remaining character belongs to the value, so a string value may itself contain colons.
Return true if every record contains every schema key exactly once, contains no extra keys, and gives every key the required runtime type. An int value must be a canonical signed decimal integer: 0, a positive number without leading zeros, or a negative number whose magnitude has no leading zeros. Otherwise, return false.
The entries inside a record may appear in any order. An empty dataset is valid.
Function
validateDataset(schema: String[], records: String[][]) → booleanExamples
Example 1
schema = ["name:str","age:int","group:str"]records = [["name:str:Ada","age:int:31","group:str:search"],["group:str:ads","age:int:-4","name:str:Lin"]]return = trueBoth records contain exactly the three schema keys, and every runtime type and integer representation is valid.
Example 2
schema = ["name:str","age:int"]records = [["name:str:Ada","age:str:31"]]return = falseThe value for age carries the runtime type str, but the schema requires int.
Example 3
schema = ["message:str"]records = [["message:str:ready:now"],[]]return = falseThe colon in the first string value is allowed, but the second record is missing the required key.
Constraints
1 <= schema.length <= 500 <= records.length <= 2000 <= records[i].length <= 50- Schema keys are unique and each schema entry is well formed with type
strorint. - Keys and encoded values contain at most 100 characters.