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": "bharmony103@gmail.com",
"age": 16,
"job": null,
"company": null
}
},
"104": {
"person": {
"name": "Jikul",
"email": "jikul@hotmail.com",
"age": 38,
"job": "Founder - Packfora",
"company": "Packfora"
}
}
},
"Sobha_Rose": {
"101": {
"person": {
"name": "Arya Aravind",
"age": 25,
"email": "arya@arvind.com",
"job": "Software Engineer",
"company": "Akx software solutions"
}
},
"103": {
"person": {
"name": "Jackson Paul",
"age": 65,
"email": "paul_jackson@gmail.com",
"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