Which required fields are missing
A form submission arrives as a bag of strings and the server checks it before touching the database.
- A field is missing when its key is absent, or its value is empty or only whitespace.
- Report them in the order the requirements were given, not the order the payload happens to be in.
- Nothing required means nothing missing.
MissingFields(payload: map<string, string>, required: list<string>) → list<string>
C# needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.
Where you start
public List<string> MissingFields(Dictionary<string, string> payload, List<string> required) {
}
Worked examples
| Call | Result |
|---|---|
MissingFields(new Dictionary<string, string> { { "name", "Ada" }, { "email", "" } }, new List<string> { "name", "email", "phone" }) | new List<string> { "email", "phone" } |
MissingFields(new Dictionary<string, string> { { "name", " " } }, new List<string> { "name" }) | new List<string> { "name" } |
MissingFields(new Dictionary<string, string> { { "name", "Ada" } }, new List<string> { "name" }) | new List<string> { } |
MissingFields(new Dictionary<string, string> { }, new List<string> { }) | new List<string> { } |
Hint
Walk the requirements, not the payload — that is what fixes the output order.
Reference solution in C#
public List<string> MissingFields(Dictionary<string, string> payload, List<string> required) {
var result = new List<string>();
foreach (var key in required) {
if (!payload.ContainsKey(key) || payload[key].Trim().Length == 0) result.Add(key);
}
return result;
}