Kafkaesque

From programming_contest
Revision as of 02:22, 2 November 2021 by Kmk21 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This problem gives us a list of integers and asks, if we can only "process" the elements in order of their value, but must visit them in order by their index, how many times do we have to traverse the list to process all elements?

The input size (100) is small enough that we can simply simulate the process. Alternatively, we realize that any time we have a lower value after a higher one, we must necessarily go through the list another time. This allows us to iterate through the input a single time, checking for the count of elements which have a lower value than their predecessor.