Kafkaesque: Difference between revisions

From programming_contest
Jump to navigation Jump to search
Created page with "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 d..."
 
No edit summary
 
Line 7: Line 7:
[[Category:Algorithm Trivial]]
[[Category:Algorithm Trivial]]
[[Category:Implementation Trivial]]
[[Category:Implementation Trivial]]
[[Category:Simulationl]]
[[Category:Simulation]]

Latest revision as of 02:22, 2 November 2021

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.