Amazon Interview Question
Quality Assurance EngineersCountry: India
Interview Type: In-Person
Below piece of code is written in c# but not tested.
///Code for get response from the given url
private HtmlDocument HttpClient()
{
HtmlDocument docuemnt = new HtmlDocument();
var httprequest = (HttpWebRequest)webrequest.create(url));
using(streamReader reader = new streamReader(httprequest.GetResponse().GetResponseStream()))
{
doucment.LoadHtml(reader.ReadToEnd());
reader.close();
}
return docuement;
}
public void SortIntegerInAscendingOrder()
{
HtmlDocuement document = HttpClient();
int[] number = new int[];
HtmlNodeCollection nodeCollection = docuement.docuementNode.SelectNodes("xpath for specific TAG");
if (nodeCollection != null)
{
foreach(HtmlNode node in nodeCollection)
{
number.Add(node.value);
}
//selection sort technique;
Sorting(number);
}
}
private void Sorting(int[] number)
{
//Here use selection sort technique
}
There are multiple pieces at work here. At least:
- JW March 20, 20151. URL to open HTML page
2. TAG finding algorithm
3. Sorting algorithm
You'd want to test each of these areas with some combination of input. Below gives an idea of where to start.
Normal cases:
- Open URL to HTML page has a mixture of desired tag and random other tags
Edge cases:
- HTML page has nothing but one of the desired tag with one number
- HTML page has only undesired tags
- Tags contain max/min number allowed
- Tags contain negative numbers
Weird cases:
- Make tag data already sorted, or sorted in reverse
- Tags all contain the same number
Extreme cases:
- A massive HTML file with enough of the desired tag to cause some overflow
- Tags contain numbers too big for datatype being used (ex. 32-bit integer)
Invalid input:
- Provide invalid URL
- Provide desired tag in HTML but with no number inside it
- Provide empty HTML page