fly123
BAN USER- 1of 1 vote
AnswersYou are given two array lists. One Array List contains information of latitudes and longitudes of all the amazon stores and another array list contains all the possible values of latitudes and longitudes. Find an optimal way to find out all the latitudes and longitudes which are nearest to one pair of amazon store.
- fly123 in United States
ArrayList<latitude, longitude> AmazonStore;
ArrayList<latitude, longitude> World;| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Coding - 1of 1 vote
AnswersWrite a function that gets a number n and prints out a random list
- fly123 in United States
of numbers 1..n to the screen. For example:
randlist(5) : 1 5 3 2 4
randlist(6) : 4 6 1 5 3 2
This should be truly random (uniformly spread) and with a O(n) complexity.
Every number should appear only once. Random(n) is given as a tool you can use to generate a
single random number between 1-n| Report Duplicate | Flag | PURGE
Microsoft Software Engineer in Test Coding
void randlist(int x)
{
ArrayList<int> buffer = new ArrayList<int>();
int random_integer;
for(int i=0; i<x; i++)
{
random_integer = ((rand)%x)+1
if(buffer.contains(random_integer)
{
continue;
}
buffer.add(random_integer)
}
for(int i=0; i<buffer.lenght;i++)
{
System.out.println(buffer.Element);
}
}
RepRichardWParks, Accountant at ADP
I think the best way to go about this would be via shuffling. The knuth shuffle problem is a much better approach for this
- fly123 February 01, 2013