LIST PACKING Problem statement
Given an array of uppercase (don't delete) and lowercase (do delete) characters:
- Delete the lowercase
- Compact the (remaining) uppercase characters to the low end of the array.
Note, "uppercase" and "lowercase" are just examples of "don't delete" and "do delete".
Example
Algorithm
- Assign a 1 to each uppercase entry, assign a 0 to each lowercase entry.
- perform prefix sum on the 0s and 1s.
- for each value (do this in parallel),
- if uppercase, store in location given by prefix sum
- if lowercase, do nothing
- Notice! last prefix sum value gives the number of packed values.
Example