Skip to content

Instantly share code, notes, and snippets.

@polyglothacker
Last active June 10, 2022 05:17
Show Gist options
  • Save polyglothacker/1610bba79286979e0bb4c5d34bca3903 to your computer and use it in GitHub Desktop.
Save polyglothacker/1610bba79286979e0bb4c5d34bca3903 to your computer and use it in GitHub Desktop.
Let us say you have the following data for all apartments in a locality inside a city. For this problem the city is assumed to be
Bangalore.
{
"whitefield": {
"varthur": {
"Brigade_Harmony": {
"103": {
"person": {
"name": "Pranav Anand",
"email": "[email protected]",
"age": 16,
"job": null,
"company": null
}
},
"104": {
"person": {
"name": "Jikul",
"email": "[email protected]",
"age": 38,
"job": "Founder - Packfora",
"company": "Packfora"
}
}
},
"Sobha_Rose": {
"101": {
"person": {
"name": "Arya Aravind",
"age": 25,
"email": "[email protected]",
"job": "Software Engineer",
"company": "Akx software solutions"
}
},
"103": {
"person": {
"name": "Jackson Paul",
"age": 65,
"email": "[email protected]",
"job": "Professor Emeritus",
"company": "University of Bangalore"
}
}
}
}
}
}
Create a logic/data structure which is able to use this data and then answer these kind of search queries.
1. query => "/whitefield/varthur/Brigade_Harmony/" -> {"103": ..., "105": ..., "203": ...}
2. query => "//Sobha_Rose/101/person" -> {"name": "Arya Aravind", ...}
3. query => "//person[age=65] -> {"name": "Jackson Paul", "age": 65, ...}
Basically this is an XPath inspired problem but you are not supposed to use XPath or XML to solve the problem. Instead it
should be done from first principles (design from scratch).
@polyglothacker
Copy link
Author

The schema in general is,

{
	"locality": {
		"sub-locality": {
			"Apartment or Building": {
				"flat number": { 
					"person": {
						"name":
						"email":
						"age":
						"job":
						"company":
					}
				}
			}
		}
	}					
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment