-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathThe_Lazy_Startup_Office.cs
More file actions
75 lines (48 loc) · 3.56 KB
/
The_Lazy_Startup_Office.cs
File metadata and controls
75 lines (48 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Linq;
namespace CodingChallenges;
[TestClass]
public class The_Lazy_Startup_Office {
/*
The Lazy Startup Office
A startup office has an ongoing problem with its bin. Due to low budgets, they don't hire cleaners. As a result, the staff are left to voluntarily empty the bin. It has emerged that a voluntary system is not working and the bin is often overflowing. One staff member has suggested creating a rota system based upon the staff seating plan.
Create a function binRota that accepts a 2D array of names. The function will return a single array containing staff names in the order that they should empty the bin.
Adding to the problem, the office has some temporary staff. This means that the seating plan changes every month. Both staff members' names and the number of rows of seats may change. Ensure that the function binRota works when tested with these changes.
Notes:
All the rows will always be the same length as each other.
There will be no empty spaces in the seating plan.
There will be no empty arrays.
Each row will be at least one seat long.
An example seating plan is as follows:
Or as an array:
[ ["Stefan", "Raj", "Marie"],
["Alexa", "Amy", "Edward"],
["Liz", "Claire", "Juan"],
["Dee", "Luke", "Katie"] ]
The rota should start with Stefan and end with Dee, taking the left-right zigzag path.
As an output you would expect in this case:
["Stefan", "Raj", "Marie", "Edward", "Amy", "Alexa", "Liz", "Claire", "Juan", "Katie", "Luke", "Dee"])
*/
[TestMethod]
public void Main() {
var testInput = new string[][] { new[] { "Bob", "Nora" }, new[] { "Ruby", "Carl" } };
CollectionAssert.AreEqual(new[] { "Bob", "Nora", "Carl", "Ruby" }, BinRota(testInput));
testInput = new string[][] { new[] { "Billy" } };
CollectionAssert.AreEqual(new[] { "Billy" }, BinRota(testInput));
testInput = new string[][] { new[] { "Billy", "Nancy" } };
CollectionAssert.AreEqual(new[] { "Billy", "Nancy" }, BinRota(testInput));
testInput = new string[][] { new[] { "Billy" }, new[] { "Megan" }, new[] { "Aki" }, new[] { "Arun" }, new[] { "Joy" } };
CollectionAssert.AreEqual(new[] { "Billy", "Megan", "Aki", "Arun", "Joy" }, BinRota(testInput));
testInput = new string[][] { new[] { "Sam", "Nina", "Tim", "Helen", "Gurpreet", "Edward", "Holly", "Eliza" }, new[] { "Billy", "Megan", "Aki", "Arun", "Joy", "Anish", "Lee", "Maryan" }, new[] { "Nick", "Josh", "Pete", "Kavita", "Daisy", "Francesca", "Alfie", "Macy" } };
CollectionAssert.AreEqual(new[] { "Sam", "Nina", "Tim", "Helen", "Gurpreet", "Edward", "Holly", "Eliza", "Maryan", "Lee", "Anish", "Joy", "Arun", "Aki", "Megan", "Billy", "Nick", "Josh", "Pete", "Kavita", "Daisy", "Francesca", "Alfie", "Macy" }, BinRota(testInput));
testInput = new string[][] { new[] { "Stefan", "Raj", "Marie" }, new[] { "Alexa", "Amy", "Edward" }, new[] { "Liz", "Claire", "Juan" }, new[] { "Dee", "Luke", "Elle" } };
CollectionAssert.AreEqual(new[] { "Stefan", "Raj", "Marie", "Edward", "Amy", "Alexa", "Liz", "Claire", "Juan", "Elle", "Luke", "Dee" }, BinRota_v2(testInput));
}
public static string[] BinRota(string[][] input) => input
.Select((string[] row, int ind) => ind % 2 == 0 ? row.AsEnumerable() : row.Reverse())
.SelectMany(x => x)
.ToArray();
public static string[] BinRota_v2(string[][] input) => input
.SelectMany((row, ind) => ind % 2 == 0 ? row : row.Reverse())
.ToArray();
}