Statistics

Problem Statement for "MirrorNumber"

Problem Statement

A number is written on a traditional digital display. If the display looks identical when flipped horizontally (i.e., around a vertical axis), the number is called a "mirror number". On a digital display, the digits 0, 1 and 8 are symmetrical, and the digits 2 and 5 are mirror images of each other. No other digits make sense when flipped horizontally. For example, 0, 101 and 1521 are all mirror numbers, while 1221 and 1010 are not (see images below). Given two Strings A and B, both representing integers with no extra leading zeroes, return the number of mirror numbers between A and B, inclusive.

Mirror numbers (both remain unchanged after mirroring):
    

Not mirror numbers (1221 mirrors to 1551, and 1010 mirrors to 0101):
    

Definition

Class:
MirrorNumber
Method:
count
Parameters:
String, String
Returns:
int
Method signature:
int count(String A, String B)
(be sure your method is public)

Constraints

  • A will represent an integer between 0 and 10^18, inclusive.
  • B will represent an integer between A and 10^18, inclusive.
  • Both A and B will have no extra leading zeros.

Examples

  1. "0"

    "10"

    Returns: 3

    There is only 0, 1 and 8 here.

  2. "0"

    "100"

    Returns: 7

    Few more: 11, 25, 52, 88.

  3. "143"

    "23543"

    Returns: 54

  4. "1234"

    "23452354235234"

    Returns: 87478

  5. "0"

    "1000000000000000000"

    Returns: 3124999

  6. "1"

    "1000000000"

    Returns: 2498

  7. "102"

    "10000000000001234"

    Returns: 624992

  8. "0"

    "200000004"

    Returns: 1374

  9. "3456"

    "365426457654646453"

    Returns: 2343720

  10. "3453426345"

    "3453453455"

    Returns: 0

  11. "64575675"

    "6786897866"

    Returns: 3500

  12. "0"

    "0"

    Returns: 1

  13. "0"

    "1"

    Returns: 2

  14. "354758"

    "456472905830476354"

    Returns: 2343600

  15. "88"

    "100"

    Returns: 1

  16. "84902"

    "3464576867980563"

    Returns: 468656

  17. "9999999"

    "10000001"

    Returns: 1

  18. "9999999999999"

    "10000000000001"

    Returns: 1

  19. "999"

    "100000001"

    Returns: 981

  20. "4762198"

    "23456456456345"

    Returns: 87150

  21. "22"

    "333333333"

    Returns: 1745

  22. "200004"

    "200000004"

    Returns: 1250

  23. "0"

    "20000004"

    Returns: 624

  24. "0"

    "20000000000005"

    Returns: 78125

  25. "200000000000000004"

    "200000000000000005"

    Returns: 1

  26. "1"

    "825522225255552258"

    Returns: 2948437

  27. "0"

    "985218125012580150"

    Returns: 3124999

  28. "12345"

    "98765432198765432"

    Returns: 1562452

  29. "502"

    "299999995212555555"

    Returns: 2343736

  30. "2"

    "1000000000000000000"

    Returns: 3124997

  31. "135"

    "88828888888888828"

    Returns: 1558740

  32. "183410081237571912"

    "988018741012831234"

    Returns: 1203125

  33. "2123521082"

    "2172858103"

    Returns: 35

  34. "51555122212"

    "1555555522222220"

    Returns: 361688

  35. "1328500121615471"

    "810120434455345681"

    Returns: 2457575

  36. "11"

    "700000000000000000"

    Returns: 2734371

  37. "0"

    "100000000000000"

    Returns: 124999

  38. "13132134124"

    "2343414212431313"

    Returns: 431375

  39. "0"

    "888888888888888888"

    Returns: 3124999

  40. "582"

    "525252528252525"

    Returns: 244125

  41. "10000000000"

    "100000000000"

    Returns: 7500

  42. "456"

    "609005240670030000"

    Returns: 2734361

  43. "0"

    "4"

    Returns: 2

  44. "7"

    "85270391700472531"

    Returns: 1494997

  45. "12321"

    "1000000000000000000"

    Returns: 3124952

  46. "1435"

    "28825025883"

    Returns: 8691

  47. "458943"

    "321412341441344334"

    Returns: 2343600

  48. "1"

    "53674575473745745"

    Returns: 1234373

  49. "251"

    "285"

    Returns: 1

  50. "999999999999999999"

    "999999999999999999"

    Returns: 0

  51. "12"

    "12545674000005678"

    Returns: 752495

  52. "0"

    "3"

    Returns: 2

  53. "888888888888888888"

    "1000000000000000000"

    Returns: 1

  54. "1"

    "999999999999999999"

    Returns: 3124998

  55. "1"

    "1000000000000000000"

    Returns: 3124998

  56. "151"

    "171"

    Returns: 0

  57. "111111111111111111"

    "999999999999999999"

    Returns: 1464844

  58. "0"

    "109"

    Returns: 8

  59. "707"

    "10770"

    Returns: 25

  60. "0"

    "53"

    Returns: 6

  61. "23135165316"

    "999999999999999999"

    Returns: 3117000

  62. "1521"

    "85555555822222228"

    Returns: 1503884

  63. "58"

    "100"

    Returns: 1

  64. "867254749"

    "1013063236"

    Returns: 115

  65. "123"

    "1000000000000000000"

    Returns: 3124990

  66. "52355"

    "463412312312312347"

    Returns: 2343672

  67. "888888888"

    "11111111111111111"

    Returns: 681096

  68. "3"

    "76"

    Returns: 4

  69. "0"

    "9"

    Returns: 3

  70. "81"

    "81"

    Returns: 0

  71. "8"

    "25008888188880025"

    Returns: 1001871

  72. "73"

    "104"

    Returns: 2

  73. "1251"

    "1251"

    Returns: 1

  74. "0"

    "23"

    Returns: 4

  75. "12312312"

    "125000821085212"

    Returns: 148824

  76. "222555"

    "222555"

    Returns: 1

  77. "0"

    "99999999999999999"

    Returns: 1562499

  78. "0"

    "1000000"

    Returns: 199


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: