Amazon Interview Question for Software Engineer / Developers
- 0of 0 votes
AnswerDesign an object oriented console application named universe that reads in a file containing the schema of a two
- AnonD June 24, 2015 in United States
dimensional (2D) universe and outputs certain information about the universe.
A 2D universe is a simplified universe that contains galaxies, stars, and planets, all of which are located on a flat plane
specified using 2-coordinates (x-axis and y-axis).
There is only one universe and it contains one or more galaxies.
A galaxy may contain one or more stars located in it.
A star may contain zero or more planets located near it in the same galaxy.
A planet may belong to one or two stars located near it in the same galaxy (Planet E465D in the sample file below is an example).
In order to allow the objects to support more descriptive attributes and functionality in future revisions of the
application, all the object types described above should be represented using separate classes. Parent-Child relationships should also be represented using links between the various object instances.
The program will run with three arguments specified: the input-file, and the name of two objects of any type, A and B.
Example command-line: universe text.txt Alpha_Dra E465D
Based on the command line arguments specified, the program will compute and display:
1. The parents location for both object A and B. (If needed, assume the coordinate of the universe is 0,0)
2. The minimum distance between object A (Alpha_Dra) and B (E465D). This is the distance between the two objects
given locations.
3. Any of the two closest stars in the entire universe.
4. The farthest object from A, that is of the same type as A; and the farthest object from B, that is of the same type as
B. (if one exists)
The input file contains new-line separated lines each describing one object using the format:
Type|Unique-Name|X-Coordinate|Y-Coordinate|Parent’s-Name|
Example test.txt input file:
Galaxy|Draco|75434.2|89151.4|Universe|
Star|Beta_And|23315.83|-2234.73|Andromeda|
Star|Alpha_Dra|75243.25|84123|Draco|
Galaxy|Andromeda|2967.78|-2357.2|Universe|
Planet|P165EU|75242.42|84121.2|Alpha_Dra|
Star|Alpha_And|26413.83|-2727.73|Andromeda|
Planet|E465D|26412.4|-2726.51|Alpha_And|
Planet|E465D|26412.4|-2726.51|Beta_And|
Notes:
The Universe object that serves as a parent to the galaxies is implicit, and will not be explicitly defined in the input
file.
The input lines may occur in any order
The file may contain millions of lines.
Example output of running: universe test.txt Alpha_Dra E465D
Parent of Alpha_Dra is located at: 75434.2,89151.4
Parent of E465D is located at: 26413.83,-2727.73
Distance between Alpha_Dra and E465D: 99635.8
Closest two stars in the universe are: Alpha_And and Beta_And| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm
Interview Type: Written Test
How can we determine the location of parent when a planet/star has two stars/galaxies as parents? I see one such(E465D) in the sample input file above.
- rakhee63 June 30, 2015