Statistics

Problem Statement for "SearchDisks"

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.

Definition

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

Constraints

  • 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

Examples

  1. "beatles queen abba"

    "abba"

    Returns: 0

    It is not necessary to take out any disks. "abba" is already on top.

  2. "beatles queen abba"

    "beatles"

    Returns: 2

    It is necessary to take out "abba" and then "queen" to get to "beatles".

  3. "a b c"

    "a"

    Returns: 2

  4. "a b c"

    "b"

    Returns: 1

  5. "a b c"

    "c"

    Returns: 0

  6. "c b a"

    "c"

    Returns: 2

  7. "c b a"

    "b"

    Returns: 1

  8. "c b a"

    "a"

    Returns: 0

  9. "xeywyxpvwi ncehqsybcnfgjkwtvrkhoommnbwlafymsiftcmh"

    "xeywyxpvwi"

    Returns: 1

  10. "vcuionwlb mobmwqeeprptduomoalpnpnfwmebbkcfeunxtfpi"

    "vcuionwlb"

    Returns: 1

  11. "jtfymszirquvptgxoruihecijpsfooxqxnffmzyqh sjjmhmju"

    "sjjmhmju"

    Returns: 0

  12. "ujvrnsvacptzvrihqkykarqkxtukfzkgpvnocalobt lehdkav"

    "lehdkav"

    Returns: 0

  13. "umfmlnkkogqsfsrguyzqiajyaqfahvbwvkbijakewxx uctqzf"

    "uctqzf"

    Returns: 0

  14. "qmmzf erzbzidonkkkxmwciqsevwfdvpwwahvrspakevxrvicq"

    "qmmzf"

    Returns: 1

  15. "jfjk xqfmgftwavfohelxlgmglpykrlqguzfblapmjbgynzwhr"

    "jfjk"

    Returns: 1

  16. "auo rjfpbserogfzohqgdoeidoqkenkjndnnjfkpxpweeaevgf"

    "auo"

    Returns: 1

  17. "bs lgjulmllkdepqosvjczszueahrljeygxymscokxkkubqwxf"

    "bs"

    Returns: 1

  18. "oltlprnsnxwcctxbhgybzxmuukfnlssyrsevgyvlpxvjirut k"

    "k"

    Returns: 0

  19. "eujhtal kxwab lwqvqnu iaggutzcmejia"

    "kxwab"

    Returns: 2

  20. "bruwxbtxwx eaamnfti noqdagcgfstvprobib"

    "eaamnfti"

    Returns: 1

  21. "ibdl uckymnjd phoestxhwejnamavhxe aivls imou stlc"

    "imou"

    Returns: 1

  22. "appxwtbj ddmsk ecvdfkurtkezemlze pnemr"

    "ddmsk"

    Returns: 2

  23. "povjisdxfkf vvlo fmncvaruvtwternoc uaqd uxigzzmxq"

    "uxigzzmxq"

    Returns: 0

  24. "bodhirxjsb bibrmosveqtfxtwe hcinfza"

    "hcinfza"

    Returns: 0

  25. "ggupuh iivdjjhtrp cvzjk qrdtsvzrifuyc zvu"

    "iivdjjhtrp"

    Returns: 3

  26. "nqgdqtniadryxlhntktr wnptxg yob nhto"

    "nhto"

    Returns: 0

  27. "p smfrrxokdyetl lfkgcijtmh sjncyz rvxzvnro ik"

    "sjncyz"

    Returns: 2

  28. "yqqacjpwprkosvdr ljawcdp vgiwhyicdh qu bd"

    "qu"

    Returns: 1

  29. "hazrkys npsqn sick aya darphbetgchpsnjkj ofu"

    "sick"

    Returns: 3

  30. "xts umxtlimundjd zdktnewu uruf levn wsnfksqh"

    "uruf"

    Returns: 2

  31. "ebqdkikz jwlsniwxao salcoqg hvtzwphlkpjigjqxag m"

    "jwlsniwxao"

    Returns: 3

  32. "ziwinjckbukbqxc hnez espejjdqfgph"

    "hnez"

    Returns: 1

  33. "ubqnmltmrcqimg rhhd bxjvv"

    "rhhd"

    Returns: 1

  34. "u rkefbqliqab vyvushxq pfaxwrdykcrmeikcgrj"

    "u"

    Returns: 3

  35. "mcxybiktd ncjuckvgzrjdczlnf kgdvactpy llmtjkioajr"

    "mcxybiktd"

    Returns: 3

  36. "bcglbhxvbidjihjm nmugfyghooyktmfommj vtd"

    "vtd"

    Returns: 0

  37. "foxcmwqx wjmfvsigkjypxycm n ncqwwiusap ylbabszgv"

    "foxcmwqx"

    Returns: 4

  38. "x xsurhixf vlmeyej hz iwbiojgmxdqzdzriwb"

    "hz"

    Returns: 1

  39. "yfqsymfxbhondlwk hkienendpda mtj bufhjarkpv i"

    "mtj"

    Returns: 2

  40. "oheqwjenhtboxujhi raymcpfmxwyl ynp xlafxcfgcx"

    "xlafxcfgcx"

    Returns: 0

  41. "rmfdxrov szonuuop uekkhos yawc yvcgfgmucks"

    "rmfdxrov"

    Returns: 4

  42. "obxhlq gkrwetkhvxxbaju sttdbsg vyyyey mpmgkyxh"

    "sttdbsg"

    Returns: 2

  43. "hyiqoauobwefudws rvikoaq oma sffnpupvfjebkvkbd"

    "oma"

    Returns: 1

  44. "hbdlgmhaghseau t lguppc vwilhiv yd owxbbl ba"

    "ba"

    Returns: 0

  45. "x xaglmhfcnpnouymyrw kaf azfihyuvnez u"

    "kaf"

    Returns: 2

  46. "xumeobac szfo skxpnpsz w lefappcrfzp kjqrzjqs"

    "w"

    Returns: 2

  47. "ooyeqnlnmakvvmzac sfc tux azfguzoqhemsxqsjafca w"

    "w"

    Returns: 0

  48. "qvvqjcskvx ntovb pmqquz po huwfpmgmqgnyu ppydxmsyg"

    "ntovb"

    Returns: 4

  49. "l e v p i u g b x k d r c j f n t q w y h a z m o"

    "y"

    Returns: 5

  50. "x h k d j z y f i s e v g b a t m l u c n p r o q"

    "p"

    Returns: 3

  51. "r a x l w n s d j m y h z o v f q k b u g p t e i"

    "y"

    Returns: 14

  52. "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"

    "f"

    Returns: 11

  53. "m y k l i o t p e s b r a h n g q w x u d j z c v"

    "l"

    Returns: 21

  54. "y o v s c w n q u d a p h l t f z b x g e m r j k"

    "j"

    Returns: 1

  55. "p f e j h s w z g t x i u y a v q c n d b k m r o"

    "g"

    Returns: 16

  56. "m b y h z j l i g c s r x p n q v f o u w e k a d"

    "g"

    Returns: 16

  57. "b h s f j k o v c g q l d t i u y m a p x r e w z"

    "k"

    Returns: 19

  58. "t k j a r o w p y i z u q g b f e x c v s n d l m"

    "j"

    Returns: 22


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: