TopCoder problem "SearchDisks" used in TCHS07 Alpha Round 1 (Division I Level One)

Problem Statement

    You have a lot of CDs that you have placed into one big box. You are given a String diskNames containing a single-space separated list of the disk names (the names will not contain spaces). The first disk is at the bottom of the box, the second lies directly on top of the first disk, and so on. Return the number of disks you'll need to take out of the box to find the disk named searchingDisk. You only need to take out the disks that are on top of searchingDisk. You do not need to take out the disk you're looking for.


Parameters:String, String
Method signature:int numberToTakeOut(String diskNames, String searchingDisk)
(be sure your method is public)


-diskNames will contain between 1 and 50 characters, inclusive.
-searchingDisk will contain between 1 and 10 characters, inclusive.
-diskNames will contain only lowercase letters ('a'-'z') and spaces (' ').
-searchingDisk will contain only lowercase letters ('a'-'z').
-Disk names will be separated by exactly one space in diskNames.
-searchingDisk will be one of the disk names in diskNames.
-diskNames will not contain duplicate disk names.
-diskNames will not contain leading or trailing spaces


"beatles queen abba"
Returns: 0
It is not necessary to take out any disks. "abba" is already on top.
"beatles queen abba"
Returns: 2
It is necessary to take out "abba" and then "queen" to get to "beatles".
"a b c"
Returns: 1
"t k o h z s v r i c e d n f a m u w p g j q x y l"
Returns: 11

Problem url:

Problem stats url:




PabloGilberto , brett1479 , Olexiy

Problem categories:

Simple Search, Iteration, String Parsing