sathley
BAN USERStep 1 : Sort the million phone numbers.
Step 2 : Store the first phone number at location 0 and at all the subsequent locations just store the difference between the current number and the previous number.
eg : hypothetical sorted phone numbers : 55555, 55556, 55557, 55559...
get stored as 55555, 1, 1, 2...
I assume the money I have with me to invest in stocks. Now that I already know how the stocks fluctuated during the given time period, all I have to do is find the time period where the stock prices increased the most and buy and sell accordingly.
public int PickStocks(int[] input)
{
const int moneyIHave = 100;
int maxDiff = 0;
for (var i = 0; i < input.Length;i++)
{
for (var j = i+1; j < input.Length; j++)
{
if(input[j] - input[i] > maxDiff)
{
maxDiff = input[j] - input[i];
}
}
}
if(maxDiff == 0)
return 0;
else
{
return moneyIHave * maxDiff;
}
}
public void PrintRepeatCustomers()
{
Console.WriteLine("Enter path to log file.");
var path = Console.ReadLine();
if (path == null) return;
var lines = File.ReadAllLines(path);
var listLines = lines.ToList();
//logs will only contain the last visit timestamp of customer
var logs = new Dictionary<long,DateTime>();
foreach (var line in listLines)
{
var terms = line.Split(':');
var customerId = long.Parse(terms[1]);
var timestamp = DateTime.Parse(terms[0]);
if(logs.ContainsKey(customerId) && timestamp - logs[customerId] < TimeSpan.FromDays(1))
{
Console.WriteLine(customerId);
}
logs[customerId] = timestamp;
}
}
DP = Dynamic Programming
- sathley April 02, 2013