using System.Collections.Generic;
namespace Aitheon.Interview
public static void Main()
var source = new int[] { 4, 3, 4, 4 };
var destination = new int[] { 2,6,8};
var computeInstance = IntegerArrayCompute.GetInstance(source, destination);
var result = computeInstance.Compute();
PrintComputeResult(result);
private static void PrintComputeResult(int[] result)
Console.WriteLine(string.Join(',', result));
public interface IArrayCompute
public class IntegerArrayCompute: IArrayCompute
private IntegerArrayCompute()
Source = new Stack<int>();
Destination = new Stack<int>();
Result = new Stack<int>();
private IntegerArrayCompute(Stack<int> source, Stack<int> destination)
Destination = destination;
Result = new Stack<int>();
public static IntegerArrayCompute GetInstance(int[] source, int[] destination)
throw new Exception("Missing source");
if (destination == null) {
throw new Exception("Missing Destination");
var numberOfElementsInSource = source.Length;
var numberOfElementsInDestination = destination.Length;
return new IntegerArrayCompute(GetInputArrayAsStack(source, Math.Max(numberOfElementsInSource, numberOfElementsInDestination) - numberOfElementsInSource),
GetInputArrayAsStack(destination, Math.Max(numberOfElementsInSource, numberOfElementsInDestination) - numberOfElementsInDestination));
private static Stack<int> GetInputArrayAsStack(int[] elements, int numberOfZeroesToPrePopulate)
var stack = new Stack<int>();
for (int i = 0; i < numberOfZeroesToPrePopulate; i++)
foreach (var element in elements)
int numberOfIterations = Source.Count
, operationResult = Int32.MinValue
for(; index < numberOfIterations -1; index++)
operationResult = PerformCompute(Source.Pop(), Destination.Pop(), index, carryOver);
carryOver = operationResult / 10;
var valueToStore = operationResult % 10;
Result.Push(valueToStore);
Result.Push(PerformCompute(Source.Pop(), Destination.Pop(), index, carryOver));
private int PerformCompute(int source, int destination, int index, int carryOver) {
return source + carryOver - destination;
return source + carryOver + destination;