Dataset Schema Validator
Updated
Problem statement
You are given a dataset schema and a list of records. Check whether every record matches the schema.
The schema is an array of unique entries of the form key:type. A schema type is either str or int.
Each record is an array of entries of the form key:type:value. The first colon ends the key. The second colon ends the runtime type, which is the type the record gives for that value. Everything after the second colon is the value, so a string value may contain colons of its own.
Return true if every record follows all of these rules:
- It has every schema key exactly once.
- It has no keys that are not in the schema.
- Each key has the runtime type that the schema requires.
An int value must also be a canonical signed decimal integer, meaning it is written in its one standard way: 0, a positive number without leading zeros, or a negative number with no leading zeros after the minus sign. 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 have exactly the three schema keys name, age and group, each once. The second record lists them in a different order, which is allowed. Every runtime type matches the schema, and both age values are valid integers. So the answer is true.
Example 2
schema = ["name:str","age:int"]records = [["name:str:Ada","age:str:31"]]return = falseThe record gives age the runtime type str, but the schema says age must be int. So the answer is false.
Example 3
schema = ["message:str"]records = [["message:str:ready:now"],[]]return = falseIn the first record, the value is ready:now. Its colon is fine, because everything after the second colon belongs to the value. The second record is empty, so it is missing the required key message. So the answer is false.
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.
More Pinterest Onsite Interview questions
- Minimum Bus Routes to a DestinationPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Delete and Compact a Forest SubtreePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Filter Pins by Excluded IDsONSITE INTERVIEW · Seen Oct 2026
- Top-Scoring Items in a Time WindowONSITE INTERVIEW · Seen Oct 2026
- Optimal Account BalancingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Escape Room LeaderboardPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Policy Violation Set ChecksONSITE INTERVIEW · Seen Sep 2026
- Shortest Sequence of Source SubsequencesONSITE INTERVIEW · Seen Sep 2026
- Insert Addition and Multiplication OperatorsONSITE INTERVIEW · Seen Sep 2026
- Unique Active Pins by Time SegmentONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Invoice / Payment ReconciliationStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW
- Serialize and Deserialize a String Key-Value StoreByteDance · ONSITE INTERVIEWByteDance interview questions
- Dictionary Records to an Editable XML TreeSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
- Deep Merge with a Conflict ResolverAutodesk · ONSITE INTERVIEWAutodesk interview questions
- Nested Template Variable ExpansionFigma · ONSITE INTERVIEWFigma interview questions
- Evaluate Sequential Variable AssignmentsGoogle · ONSITE INTERVIEWGoogle interview questions
- JSON Schema Object ValidatorDocuSign · ONSITE INTERVIEWDocuSign interview questions