Statistics

Problem Statement for "PostOffice"

Problem Statement

A new device is being designed for all the post offices in Byteland. This device will make mail classification and delivery more efficient by automatically recognizing the addresses written on envelopes. You are responsible for the software component that determines if two addresses match.

Given two Strings address1 and address2, determine if they match using the following procedure. First, remove all spaces from both addresses. Then, perform a case-insensitive string comparison. If the two strings are equal, return -1. Otherwise, return the leftmost 0-based position at which they differ (the index after removing the spaces).

Definition

Class:
PostOffice
Method:
matchAddress
Parameters:
String, String
Returns:
int
Method signature:
int matchAddress(String address1, String address2)
(be sure your method is public)

Constraints

  • address1 and address2 will each contain between 0 and 50 characters, inclusive.
  • address1 and address2 will contain only letters ('a'-'z', 'A'-'Z'), digits ('0'-'9'), and spaces.

Examples

  1. "145 West 44th Street"

    "145 west 44 th street"

    Returns: -1

    After all spaces are removed, the two addresses become: "145West44thStreet" "145west44thstreet" These two strings are equal if you do a case-insensitive comparison, so -1 is returned.

  2. " wall street "

    "WallStreet"

    Returns: -1

    Again, these two addresses are equal after all spaces are removed and a case-insensitive comparison is done between the resulting strings.

  3. " Wall Street"

    " Waal Street"

    Returns: 2

    First, remove the spaces: "WallStreet" "WaalStreet" These strings differ at position 2 (0-based). The first string has an 'l' at that position while the second string has an 'a'.

  4. "XkfitRvn CNR"

    "x kfitrVn CNR"

    Returns: -1

  5. " lU36wI 9 hTvUsoLN73wa6cAvH9x"

    " lU3 6wI 9 HTvUSoLN73W a6C AVH9x"

    Returns: -1

  6. " ohRsYy6HgsAQ4"

    " ohRsy y6HgsAQ4"

    Returns: -1

  7. " onNk yF hQ CJJnz LOKrB o"

    " onNk yF hQ c jJN z LOk rB O"

    Returns: -1

  8. "gK De0q4S8mKZT5xrr8pPXMZWmHSaER"

    "gKDe0q4s 8mk ZT5X rr8pPXmZWmHSaer"

    Returns: -1

  9. "Ts8 XYoXc8o 56bAraoONO3QFjDSpnViWXY hg"

    "Ts8 XYoXC 8O 56bARaoONo3QfjDSpnViWXY H g"

    Returns: -1

  10. "KLlbNndabM1Xud 4I q1GmpGv vM"

    "KlLB nnD abM1XUD 4 I q1GMpGv vM"

    Returns: -1

  11. "Ja B e HB6zXEvfFTgtT"

    "j a B e HB6zXEvffTgT T"

    Returns: -1

  12. "R9V i 5j7iHPH2mp76 BhdzFNp"

    "R9V i 5J7iHp H2mp76 BhdzFNp"

    Returns: -1

  13. "syL3dy"

    "syl3Dy"

    Returns: -1

  14. "dsDzsH6pf fvdviyd"

    "dsDZsH6 Pf Fvdviyd"

    Returns: -1

  15. "FsYyQfuV FKgs daCNbXT78 BHmUTb ucw"

    "FsyyQfU v Fkgs dacNbxT78 b HmUTB ucw"

    Returns: -1

  16. " JJI iyDrmozne4Wh QcvCk 9xDjI4"

    " Jj IiYdrmozne4w h QcvCk 9xDJ i 4"

    Returns: -1

  17. "dX5y FsDtpK3"

    "dX5y FsDtP K3"

    Returns: -1

  18. "H zQfhLjR S VDAF c NU23G Sq 1faYLvGu9"

    "H zqfhLJr S VDAF c n U23G Sq 1F ayLV gu9"

    Returns: -1

  19. " nW d8nDA z9UYqQ10BM"

    "nW d8ndA z9UYqq 10BM"

    Returns: -1

  20. "pPRnDAJr3 Mf ij oYPG5FjB"

    "pPrndAJr3 Mfij oYPG5f jB"

    Returns: -1

  21. "CGa"

    "CGa"

    Returns: -1

  22. "tuY8vOaviT38Bsn"

    "tuy8V OaV I t38BsN"

    Returns: -1

  23. "sf b9 T6uZPBPlq7H oxnSyO"

    "sf b9 t6uZPBpLq7H oxNsYO"

    Returns: -1

  24. "IbA2CI"

    "Ibl2CI"

    Returns: 2

  25. "bLoe0FCWCd0OA PhN9 T15"

    "bLoe0f CWcd0o O phN9T1 5"

    Returns: 12

  26. "AlAZxeqOlhU 7Hby5 0"

    "Alaz xeqOlhU 7Hby5 0"

    Returns: -1

  27. "fGmmSks2tFd3A"

    "fg mMs K s2tFd3 m"

    Returns: 12

  28. "h4uA j e 1dWX X"

    "h4ud j e 1dWX x"

    Returns: 3

  29. "wSYHe A6 0 pED EOVQANZn 7 MrEWfR"

    "wSYHE A60 pED Eo VQCNZn 7 m R EWfR"

    Returns: 15

  30. "1l8FrPfGAwc Vv 7h"

    "1L8frPfGGwc Vv 7h"

    Returns: 8

  31. "PikXD LAPJX"

    "PikXd L PJX"

    Returns: 6

  32. "Zw nZntA9G5TBKRJLsL"

    "ZwnZN tg9g5t BKrJLsL"

    Returns: 6

  33. "On3A "

    "On3O "

    Returns: 3

  34. "ZRAnskdPvB C ekYjf"

    "ZRPnskdPvb c EkYjf"

    Returns: 2

  35. "AD DykuSb5MY2 FoVw7Z wV0KX "

    "9D DykuSB 5mY2 foVw7z wV0KX "

    Returns: 0

  36. "KwACSZ "

    "kwtCSZ"

    Returns: 2

  37. "4MD3voFddIwrAvmUnhcvRIhh WQ52 "

    "4mD3V oFddIwra vmUnhcvRIHh WQ52 "

    Returns: -1

  38. "MA53Tx "

    "m753Tx "

    Returns: 1

  39. "AoZ"

    "yO Z"

    Returns: 0

  40. "j uoPAG"

    "juoPhG"

    Returns: 4

  41. "5 8Tf OtKa6Qh2M6Nd i4 v2 AWTKruauW "

    "5 8TF OtKa6Qh2m6n D I 4 v2 VWTKruauW"

    Returns: 20

  42. "WKPKy OoQ pBZZCs9Acz v"

    "WKPKy Ooq pBz ZCs9 C z v"

    Returns: 15

  43. "AD"

    "md "

    Returns: 0

  44. " A"

    "a "

    Returns: -1

  45. "Wall"

    "WallStreet"

    Returns: 4

    These strings differ at position 4 (0-based). The first string does not have a character at that position while the second string has a 'S'.

  46. "abcd"

    "bcd"

    Returns: 0

  47. "aa"

    "baa"

    Returns: 0

  48. "asdfffff"

    "asdf"

    Returns: 4

  49. "ac"

    "Ab"

    Returns: 1

  50. "abc"

    "abcd"

    Returns: 3

  51. "a1"

    "bbb"

    Returns: 0

  52. "1aa"

    "Qaa"

    Returns: 0

  53. "aeg"

    "bg"

    Returns: 0

  54. "aAd"

    "Aae"

    Returns: 2

  55. "aa"

    "abc"

    Returns: 1

  56. "aaaaa"

    "sssssa"

    Returns: 0

  57. "a"

    "bb"

    Returns: 0

  58. "fjkdsflsjflskflsf"

    "fjkds"

    Returns: 5

  59. " A"

    " "

    Returns: 0

  60. "aaaa"

    "aaaaa"

    Returns: 4

  61. "9"

    "Y"

    Returns: 0

  62. "145 West 44th Street"

    "145 west 44 th street"

    Returns: -1

  63. "Mohamed"

    "Mohkme"

    Returns: 3

  64. "B"

    "C"

    Returns: 0

  65. "abc"

    "aaaaaaa"

    Returns: 1

  66. "aaaaa"

    "0000"

    Returns: 0

  67. "abb"

    "accc"

    Returns: 1


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: