Back to problems

Optimize Log File

Algorithm · Google · Easy

Problem A log contains n entries arranged as a permutation of length n. There are also n available operations, numbered from 0 through n - 1; each operation swaps two entries. Choose any subset of these operations and perform the chosen operations in any order so that the resulting permutation is lexicographically smallest. Return that lexicographically smallest permutation. Additional notes An operation may be used no more than once. Indexing is 0-based. A permutation is an…

Checking your access…