unknown Interview Question for Software Developers

Country: United States

Comment hidden because of low score. Click to expand.
0
of 0 vote

Very hard problem here to solve.

We could go greedy on this one or do dynamic programming.

I decided dynamic programming on the board but the more I think about it might easier and cheaper to do it in a greedy algorithm.

In a greedy we can sort the task costs and keep doing task linearly comparing what is cheaper either divide or perform linearly.

Anyway here is my dynamic programming solution:

``````public int MinTaskDuration(int[] tasks, int divideCost)
{
var taskDict = Dictionary<int, int>();
foreach(var t in task)
{
{
}
else
{
}
}

}

int divideCost,
Dictionary<string, int> memo)
{
var hash = CreateHash(tasks);
if(memo.ContainsKey(hash))
return memo[hash];

if(task.Count == 0) return 0;

var tA = tasks.ToArray();

int min = int.MaxValue;
for(int i = 0; i < tA.Length; i++)
{
int a = tA[i].Key;
{
}
else
{
}

foreach(int j = i; j < tA.Legnth; j++)
{
int b = tA[j].Key;

{
}
else
{
}

var notDividing = a + b + minDuration;
var dividing = divideCost + Math.Max(a,b) + minDuration;

var temp = Math.Min(notDividing, dividing);
if(temp < min)
min = temp;

{
}
else
{
}
}

{
}
else
{
}
}

}

string CreateHash(Dictionary<int, int> tasks)
{
StringBuilder sb = new StringBuilder();

foreach(var kvp in tasks)
{
for(int i = 0; i < kvp.Value; i++)
{
sb.Append(kvp.Key + ',');
}
}

return sb.ToString();
}``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.