3 ms·
in other words, the shortest string in alphabetical order
by kayoone 7y ago
in other words, the shortest string in alphabetical order
- shric 7y agoSmallest as in order not length. In the second example with input cbacdcbc a possible solution would be cbad but acdb is "smaller" (ordered before).
- logfromblammo 7y agoIt seems odd to want to preserve the ordering among the surviving letters while still involving alphabetical order somehow. Those motives are usually mutually exclusive in the real world. As an engineer, before starting to code, I'd first ask if the customer would prefer "abcd" or "cbad" for the second example, as either would be far cheaper in terms of development and maintenance costs to do. It's somewhat common to discover that they're just taking the "acdb" you're giving them because that's exactly what they asked for, and then they're alphabetizing it to "abcd" afterward on their end, anyway. But sometimes, there is a legit reason for the weirdness, and the customer is willing to pay for the extra effort. Whenever someone seems intent on aiming at foot and pulling trigger, always ask "Are you sure?" and "Why do you want that?" at least once before helping them do what they want. The "read hypothetical; code answer" type of test doesn't quite capture that like the interactive interview discussion does.