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>
Java 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
List<String> missingFields(Map<String, String> payload, List<String> required) {
}
Worked examples
| Call | Result |
|---|---|
missingFields(Main.<String, String>mp("name", "Ada", "email", ""), Main.<String>ls("name", "email", "phone")) | Main.<String>ls("email", "phone") |
missingFields(Main.<String, String>mp("name", " "), Main.<String>ls("name")) | Main.<String>ls("name") |
missingFields(Main.<String, String>mp("name", "Ada"), Main.<String>ls("name")) | Main.<String>ls() |
missingFields(Main.<String, String>mp(), Main.<String>ls()) | Main.<String>ls() |
Hint
Walk the requirements, not the payload — that is what fixes the output order.
Reference solution in Java
List<String> missingFields(Map<String, String> payload, List<String> required) {
List<String> result = new ArrayList<>();
for (String key : required) {
String v = payload.get(key);
if (v == null || v.trim().isEmpty()) result.add(key);
}
return result;
}