pragramticProgrammer
BAN USER
- 0of 0 votes
AnswersA group of friends are tracking the miles per gallon for each of their cars. Each time one of them fills up their gas tank, they record the following in a file: His or her name The type of car they drove How many miles driven since they last filled up How many gallons purchased at this fill up Date of the fill Their data is formatted as a comma separate value (csv) file with the following format for each row:(#person,carName,milesDriven,gallonsFilled,fillupDate) Miles are recorded as floating-point numbers and gallons as integers. Please create a program that allows members of this group to determine the miles per gallon (MPG) of each of their cars during a specific time range. Note: person may have more than one so a time range query might need to output data for one or more cars. A skeleton class will be provided; your job will be to complete the program. The principal function for querying MPG is of the form (the exact name, data types, etc., can be learned by inspecting the "solution" class in the skeleton code): GetRangeMPG(PersonName, StartDate, EndDate) Returns list of objects containing (CarName, MPG) MPG is calculated as (total miles traveled during time period)/ (total gallons filled during time period. The dates you receive in the query should be treated inclusively.
- pragramticProgrammer in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 .Net/C# - 0of 0 votes
AnswersGiven as list of movies in a csv file, extract the movie name and genre and be able to return a query based on the years and the genre.
- pragramticProgrammer in United States
Basically, Parsing a CSV input file and build an indexed data storage to allow search the data in time manner.| Report Duplicate | Flag | PURGE
Amazon SDE1 .Net/C# - 0of 0 votes
AnswersGiven an Input file of IPv4 addresses, filter and write them into Valid and Invalid IPs.
- pragramticProgrammer in United States
Input file = ["192.100.0.1, "10.0.0.1", "aa.bb.cc.dd", "10.0", "999.10.10.1"]
Valid = []
Invalid = []| Report Duplicate | Flag | PURGE
Amazon Software Engineer - 0of 0 votes
AnswersLast Man Standing
- pragramticProgrammer in United States
A king gathers all the men in the kingdom who are to be put to death for their crimes, but because of his mercy, he will pardon one. He gathers the men into a circle and gives the sword to one man. The man kills the man to his left, and gives the sword to the man to the dead man's left. The last man alive is pardoned.
With 5 men, the 3rd is the last man alive.
Write a program that accepts a single parameter: a number N that represents the number of criminals to start with. The program should output the number of the last two men alive.
Example #1: myProgram 5
would output:
5, 3
Example #2: myProgram 7
would output:
3, 7| Report Duplicate | Flag | PURGE
Amazon SDE-2 - 0of 0 votes
AnswerThis is a word splitter program, I wanted to know the complexity of this program:
- pragramticProgrammer in United StatesString s = //"The quick fox jumped over a lazy dog"; "The Java language provides special support for the string " + "concatenation operator ( + ), and for conversion of other " + "objects to strings. String concatenation is implemented " + "through the StringBuilder(or StringBuffer) class and its " + "append method. String conversions are implemented through " + "the method toString, defined by Object and inherited by " + "all classes in Java."; int charLimit = 13; System.out.println("-------------"); char[] chars = s.toCharArray(); boolean endOfString = false; int start = 0; int end = start; while(start < chars.length-1) { int charCount = 0; int lastSpace = 0; while(charCount < charLimit) { if(chars[charCount+start] == ' ') { lastSpace = charCount; } charCount++; if(charCount+start == s.length()) { endOfString = true; break; } } end = endOfString ? s.length() : (lastSpace > 0) ? lastSpace+start : charCount+start; System.out.println(s.substring(start, end)); start = end+1; }
| Report Duplicate | Flag | PURGE
SDE-2 String Manipulation - 0of 0 votes
Answers/*Coding question: The customers for a particular business, required to use a webpage to select a Browse Node.
- pragramticProgrammer in United States
A Browse Node, is an element in the classification structure used to classify products in the Amazon webpage.
The products are classified in 8 categories. Each category has its own sub-classification that looks like a tree with many
children per node and many levels. The UI developer has a tool to paint such tree. He requires from you (You are the backend developer)
to implement 2 interfaces for him:
Node getRoot();
List<Node> getChildren(Node node);
The data is available for you in a text file with this format:
//nodeid, parent_node_id, nodename
Example:
//nodeid, parent_node_id, nodename
10, 1, Comedy Books
20, 2, Tablets
1, -1, Books
11, 1, Novels
12, 11, Terror novels
2, -1, Electronics
-1, 0, GlobalRoot
*/| Report Duplicate | Flag | PURGE
Amazon SDE1 Data Structures - 0of 0 votes
AnswersMinimum Continuous Subsequence: targetList & availabletTagsList are two lists of string.
- pragramticProgrammer in United States
Input:
targetList = {"cat", "dog"};
availableTagsList = { "cat", "test", "dog", "get", "spain", "south" };
Output: [0, 2] //'cat' in position 0; 'dog' in position 2
Input:
targetList = {"east", "in", "south"};
availableTagsList = { "east", "test", "east", "in", "east", "get", "spain", "south" };
Output: [2, 6] //'east' in position 2; 'in' in position 3; 'south' in position 6 (east in position 4 is not outputted as it is coming after 'in')
Input:
targetList = {"east", "in", "south"};
availableTagsList = { "east", "test", "south" };
Output: [0] //'in' not present in availableTagsList
Note: targetList will contain Distinct string objects.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm
Not a homework. This is what I wrote and couldn't wrap my head around which data structure to use as my approach would be quite inefficient.
class Car
{
public string CarName { get; set; }
public double MilesDriven { get; set; }
public int GallonFilled { get; set; }
public DateTime DateFilled { get; set; }
}
class MPGCalc
{
Dictionary<string, List<Car>> log = new Dictionary<string, List<Car>>();
public void LoadData(string inp)
{
string[] lines = inp.Split(new[] { Environment.NewLine },StringSplitOptions.None);
string personName, carName;
double milesDriven;
int gallonsFilled;
DateTime fillupDate;
List<Car> carList = new List<Car>();
foreach(var line in lines)
{
string[] info = line.Split(',');
//(#person,carName,milesDriven,gallonsFilled,fillupDate)
personName = info[0];
carName = info[1];
Double.TryParse(info[2], out milesDriven);
int.TryParse(info[2], out gallonsFilled);
DateTime.TryParse(info[4], out fillupDate);
if(log.ContainsKey(info[0]))
{
log.TryGetValue(personName, out carList);
carList.Add(new Car {CarName = personName, MilesDriven = milesDriven, GallonFilled = gallonsFilled, DateFilled = fillupDate});
log[personName] = carList;
}
else
{
carList.Add(new Car {CarName = personName, MilesDriven = milesDriven, GallonFilled = gallonsFilled, DateFilled = fillupDate});
log.Add(personName, carList);
}
}
}
}
Could you explain why you used
new Lazy<List<int>>()
also the time complexities of both the methods?
- pragramticProgrammer March 01, 2018I am not getting the required output implementing the code.
Could u explain a bit more about this comment:
//if you see an element getting inserted which is less that the
//last element remove one element from the front
//add all element list to resultList
what exactly are we adding to resultList?
- pragramticProgrammer February 01, 2018
Repleroydperry, Backend Developer at AppNexus
I am from the USA. I am 27 year old. I drive the train for my company Monk Home Funding ...
Repsharonpkarr, None at BT
Hi! My name is Mary. I am a writer for a variety of web and multi-platform applications.I am a ...
Yes the CSV would be <MovieName>,<Genre>,<Year>. This problem statement is trying to gauge the design pattern and data structure knowledge of the candidate. Should I be using a class structure and store objects in the dictionary? I am thinking that would be kind of inefficient, but cannot wrap my head around any other approach for this.
- pragramticProgrammer May 16, 2018