On Nov 7, 8:12 am, Johnson Wang <99... / 163.com> wrote:
> How to solve this problem in Ruby????
> ==============================================
> You are given a String disk representing the clusters on a disk. An 'X'
> represents a used cluster, and a '.' represents an available cluster.
> You are also given an int size representing the size, in clusters, of a
> file waiting to be written to disk. A file can only be stored in
> clusters not already being used.
> Return the minimum number of groups of consecutive clusters needed to
> store the file on the disk. (The disk does not wrap around at the end.)
> Return -1 if the disk does not have enough space available to store the
> file.
> Definition

This smells like a homework problem, so roughly:
Scan the string for groups of consecutive clusters.
Sort the clusters by length.
Iterate through the sorted group adding up the sizes and incrementing
a counter until you reach or exceed your goal.