Q38.We have a non-empty list `Location` that stores city names from the Scores dataset, sorted in alphabetical order. This results in many duplicates. The following procedure attempts to extract the unique list of cities while preserving sorted order. The pseudocode may have mistakes. Identify all such mistakes, if any.
```
uniqueList = []
uniqueList = uniqueList ++ [first(Location)]
prev = last(Location)
foreach x in rest(Location) {
if(x != prev) {
uniqueList = uniqueList ++ x
}
prev = x
}
```
Save
Check
Details
Q38
6 Aug 2023
Q38.We have a non-empty list `Location` that stores city names from the Scores dataset, sorted in alphabetical order. This results in many duplicates. The following procedure attempts to extract the unique list of cities while preserving sorted order. The pseudocode may have mistakes. Identify all such mistakes, if any.
```
uniqueList = []
uniqueList = uniqueList ++ [first(Location)]
prev = last(Location)
foreach x in rest(Location) {
if(x != prev) {
uniqueList = uniqueList ++ x
}
prev = x
}
```