City and country were typed into a web form with no validation, so the same place is in the table a dozen ways. Normalise them before anybody groups by them.
Every input row, with the columns:
contact_idcity — trimmed, every run of whitespace reduced to one space, then title case. 'UNKNOWN' if it is null or blank.country — trimmed and upper case. 'UNKNOWN' if it is null or blank.| contact_id | raw_city | country | city | country |
|---|---|---|---|---|
| 1 | new delhi | in | New Delhi | IN |
| 3 | | us | UNKNOWN | US |
| 4 | Austin | null | Austin | UNKNOWN |
trim alone does not reach those.BENGALURU, bengaluru and BeNgAlUrU must all come out as Bengaluru.'UNKNOWN'. A comparison against '' on a null column is null, not false, so the null check has to happen too.contacts| country | raw_city | contact_id |
|---|---|---|
| in | new delhi | 1 |
| IN | Pune | 2 |
| contact_id | city | country |
|---|---|---|
| 1 | New Delhi | IN |
| 2 | Pune | IN |
contacts| country | raw_city | contact_id |
|---|---|---|
| us | 3 | |
| null | Austin | 4 |
| contact_id | city | country |
|---|---|---|
| 3 | UNKNOWN | US |
| 4 | Austin | UNKNOWN |
Community-reported interview topic. Not an official company question and no affiliation is implied.
Run against the public tests, or submit to score against all of them.