Sollicitatievraag bij Microsoft

Given an array with integers, return the array so that it will not have any consecutive duplicates.

Antwoorden op sollicitatievragen

Anoniem

5 jun 2018

quickest answer is to run through array and do: check value in hash if not there then add it to hash and print if it is there do nothing O(n) in operation and memory

1

Anoniem

5 jun 2018

Previous does not fulfill the requirement for *consecutive*. Solution requires extra var: void PrintArrayNoConsecutive(int[] array) { if (array.Length > 0) { var n = array[0]; System.Println(n); for (int i = 1; i < array.Length; ++i) { if (n != array[i]) { n = array[i]; System.Println(n); } } } }