Statistics

Problem Statement for "FontSize"

Problem Statement

Graphical user interfaces rely on text routines to properly display words on various GUI components. Being able to determine the width in pixels of a line of text is useful for centering the text in a window. You will be given a sentence of letters and spaces. You will also be given the letter widths for both uppercase and lowercase letters of a particular font. You must return the width of the sentence.

Both uppercase and lowercase contain 26 elements. The first element of uppercase is the width of 'A' and the last is the width of 'Z'. The first element of lowercase is the width of 'a' and the last is the width of 'z'. The width of the space character is always 3 pixels. When a line of text is rendered, there is a gap of 1 pixel between each pair of adjacent characters.

Definition

Class:
FontSize
Method:
getPixelWidth
Parameters:
String, int[], int[]
Returns:
int
Method signature:
int getPixelWidth(String sentence, int[] uppercase, int[] lowercase)
(be sure your method is public)

Constraints

  • sentence will contain between 1 and 50 characters, inclusive.
  • sentence will only contain uppercase letters ('A'-'Z'), lowercase letters ('a'-'z'), and spaces.
  • uppercase will contain exactly 26 elements.
  • lowercase will contain exactly 26 elements.
  • Each value in uppercase and lowercase will be between 1 and 36, inclusive.

Examples

  1. "Dead Beef"

    {6,6,6,7,7,7,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9}

    {5,5,5,4,4,4,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9}

    Returns: 49

    D e a d (space) B e e f 7+1+4+1+5+1+4+1 + 3 + 1+6+1+4+1+4+1+4 = 49

  2. "Hello World"

    {7,8,8,8,7,8,8,8,7,8,8,8,8,8,7,8,8,8,8,8,7,8,8,8,8,8}

    {5,6,6,6,5,6,6,6,5,6,6,6,6,6,5,6,6,6,6,6,5,6,6,6,6,6}

    Returns: 74

  3. "Hello World"

    {7,7,7,7,7,7,7,8,7,7,7,7,7,7,7,7,7,7,7,7,7,7,9,7,7,7}

    {5,5,5,6,6,5,5,5,5,5,5,1,5,5,6,5,5,6,5,5,5,5,5,5,5,5}

    Returns: 63

  4. "ThE qUiCk BrOwN fOx JuMpEd OvEr ThE lAzY dOg"

    {36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11}

    {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26}

    Returns: 778

  5. " WWW lll MMM iii "

    {9,9,9,9,9,9,9,9,9,9,9,9,36,9,9,9,9,9,9,9,9,9,36,9,9,9}

    {9,9,9,9,9,9,9,9,1,9,9,1,9,9,9,9,9,9,9,9,9,9,9,9,9,9}

    Returns: 293

  6. "two spaces"

    {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9}

    {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}

    Returns: 43

  7. "v ktiFKHL Yc GEo"

    {4,27,3,34,11,6,17,22,25,28,20,3,5,18,35,35,18,11,28,30,19,15,10,3,23,2}

    {1,11,12,11,20,16,24,22,1,11,10,11,33,12,13,31,19,16,3,14,19,6,25,14,5,21}

    Returns: 186

  8. "dLwS SLSjxohiRMp VmEzDj gcZKRn "

    {3,1,26,21,27,23,28,6,11,9,6,29,20,31,34,26,29,36,31,23,1,1,17,30,10,31}

    {5,25,1,17,9,25,10,28,22,15,1,28,2,16,31,36,33,9,7,17,24,13,28,3,5,7}

    Returns: 602

  9. " Y S GC WkmQstWD MjpcG T"

    {16,25,34,23,18,34,17,2,8,14,21,13,18,28,2,35,36,32,17,10,18,21,15,32,21,32}

    {8,28,16,13,6,35,31,13,31,23,12,15,16,2,8,12,14,4,16,10,19,10,9,16,35,19}

    Returns: 369

  10. " nQPH U QgiXiXKa xW dWK kDHSUm ute vV hr fR"

    {18,14,14,15,22,29,8,34,25,30,35,13,9,9,28,5,31,16,24,35,7,2,12,14,21,33}

    {25,1,26,24,25,4,17,7,32,15,15,19,34,28,19,21,17,33,33,15,35,31,22,28,23,31}

    Returns: 797

  11. "i DBCHGZK jW KdZR V jj aGXpwnwTMdP iyxc"

    {17,21,6,22,29,7,20,24,28,23,17,4,27,9,29,28,33,34,11,22,31,13,10,28,35,4}

    {23,5,1,13,20,22,21,12,12,3,22,34,3,1,11,32,29,23,11,30,16,25,1,11,7,33}

    Returns: 524

  12. "y akdY yNMa W t R yrXOTfXG"

    {15,15,8,10,30,5,14,19,34,2,6,30,1,2,25,32,2,32,20,25,25,25,16,34,4,34}

    {8,31,33,35,6,31,2,36,11,36,5,26,26,12,28,35,35,25,32,24,21,5,19,8,8,23}

    Returns: 394

  13. "Nyx C k eHu ibScJWRgPcBa d NPbMxdjHlR z "

    {25,7,35,17,8,15,13,5,1,25,7,15,4,32,16,30,19,7,34,3,16,21,32,31,17,34}

    {2,22,30,30,7,27,30,36,30,12,3,25,15,14,36,1,36,6,36,15,16,27,25,4,29,35}

    Returns: 713

  14. "LDzBKVXUeyZ ziBfWho mXMqxDUICxuOp qmRC"

    {18,1,13,27,16,26,21,14,29,21,24,1,32,6,16,8,16,20,15,12,30,17,19,7,15,31}

    {34,11,11,19,4,9,28,36,26,8,33,24,9,8,14,32,6,6,21,22,21,36,23,4,4,3}

    Returns: 581

  15. "uCqKSn nkk UdwzTrN af w Aly WsgiDaeZ WOVhO w"

    {31,28,23,2,23,7,19,14,21,19,6,36,15,29,3,14,26,2,17,11,12,13,27,9,29,8}

    {19,31,32,1,11,22,14,10,16,25,9,29,19,1,22,14,18,26,1,19,4,9,18,27,31,7}

    Returns: 585

  16. " K o P HGxXN gAINhA C "

    {33,5,15,8,26,13,28,12,24,10,27,19,4,11,11,9,17,28,18,23,10,32,30,35,19,19}

    {3,24,4,21,1,10,16,14,25,18,17,2,14,5,6,2,27,7,10,30,24,3,23,22,18,7}

    Returns: 338

  17. "m pLF ifaR sRtsBk l"

    {5,36,17,35,12,11,22,18,27,32,11,19,2,31,20,24,17,17,2,1,28,17,6,24,25,10}

    {23,5,8,23,12,21,20,25,24,31,29,36,1,33,21,17,28,9,5,12,11,33,11,7,29,23}

    Returns: 303

  18. "JgGu cWbRYOTtnOO WmRH hYAl "

    {3,9,21,2,18,2,1,33,9,33,19,12,32,28,29,35,30,36,5,20,17,7,2,29,35,31}

    {31,12,17,33,2,12,11,9,35,20,19,16,26,11,11,36,28,22,31,17,34,33,28,25,25,12}

    Returns: 514

  19. "omCXKYngA i aFBSD o R QzIXOSuKt gMqpKp"

    {26,19,35,21,2,18,9,10,14,29,8,27,28,26,8,2,33,20,3,36,31,4,9,5,1,12}

    {24,29,15,9,20,2,15,20,19,21,30,32,26,1,7,27,12,24,33,29,7,29,8,35,30,33}

    Returns: 571

  20. "X kF vD ca ITh"

    {35,16,19,10,22,20,8,11,11,29,11,17,29,30,25,10,30,23,25,3,36,13,19,36,8,32}

    {19,2,32,20,23,3,10,36,27,22,31,32,15,1,26,20,28,1,29,15,13,13,34,6,6,4}

    Returns: 244

  21. "Sx iONEoP UjhuctnnkY"

    {3,23,32,1,17,4,20,2,24,21,13,2,32,31,20,16,35,9,24,15,11,31,2,13,30,4}

    {34,8,28,26,14,7,11,7,18,36,21,1,10,35,31,19,9,7,9,27,11,4,34,12,21,11}

    Returns: 443

  22. " LNjh o JQTl "

    {35,11,13,36,3,8,8,26,5,5,30,19,10,9,19,27,8,27,20,15,2,7,27,17,17,3}

    {27,18,16,20,33,3,3,16,15,8,10,33,25,24,28,35,10,19,33,24,24,19,29,9,32,34}

    Returns: 181

  23. "nQC H nqiwNc hZlD nX"

    {27,30,25,27,15,35,1,32,23,30,4,33,3,12,18,9,27,36,11,29,8,28,21,5,6,34}

    {2,32,5,19,27,23,11,7,32,9,8,27,23,2,20,27,25,18,18,30,28,34,11,5,4,30}

    Returns: 314

  24. "aVYSurDCK oNkaKr wPA KpykOUi M"

    {26,18,25,21,13,33,15,33,17,30,14,8,36,21,6,36,13,10,22,36,4,17,8,23,34,18}

    {30,1,6,12,3,8,2,3,36,29,13,33,25,31,17,10,27,5,4,12,9,7,24,26,12,9}

    Returns: 543

  25. "OOw V fha zp BOsH CqLJEQbl gRoqMKseopeszNr"

    {36,9,35,35,33,5,31,9,15,28,19,4,8,9,32,25,36,36,1,10,16,25,1,36,7,1}

    {28,9,14,24,29,21,22,30,33,28,2,21,14,36,13,5,18,15,29,35,31,15,18,11,24,10}

    Returns: 823

  26. " vKJMtl mLIPNpcl OpMW Xs GtRhBuuPbx"

    {24,36,35,24,12,28,23,14,21,8,6,5,4,18,18,23,13,9,10,3,31,35,29,28,16,16}

    {11,15,8,34,8,24,18,14,16,24,1,3,20,25,9,34,2,15,24,18,3,16,12,10,22,32}

    Returns: 527

  27. "N pfersH vw jaaySrHF SUJR W AIm z EbaV"

    {23,21,21,6,22,9,13,4,19,3,21,29,26,19,14,18,4,28,32,13,2,2,26,15,9,29}

    {16,5,9,16,13,4,19,5,3,29,1,18,10,8,11,25,6,6,8,29,21,35,12,16,33,6}

    Returns: 526

  28. "Tm mHXQVfYDyhNd fY d dlFTSg Wz n"

    {33,6,22,18,28,20,20,20,27,36,11,9,7,1,2,10,36,26,28,32,3,20,30,31,24,7}

    {8,30,36,22,8,21,11,2,1,14,11,2,13,27,23,16,19,29,4,2,16,34,15,20,29,1}

    Returns: 575

  29. " mB aNh CONele"

    {24,19,20,16,19,26,11,4,23,30,5,28,6,5,8,6,2,23,13,14,5,12,17,8,7,27}

    {10,14,30,2,36,24,26,21,9,31,31,27,10,32,32,1,8,28,26,14,8,21,10,16,11,4}

    Returns: 223

  30. " n wPyHp Aaaig yRtj gFZ f idIl "

    {29,21,3,31,30,24,24,25,2,17,13,25,10,3,17,17,17,17,25,19,29,23,3,7,2,28}

    {19,18,3,19,18,13,21,15,9,35,34,13,2,8,27,1,2,21,15,25,15,17,12,23,25,19}

    Returns: 478

  31. "LhQW XHVkDBwJCczVgKaLxRzUsEcgiln"

    {20,3,26,23,10,17,25,24,34,24,8,17,35,14,30,36,25,20,24,35,30,28,13,20,17,8}

    {22,2,31,31,12,35,3,34,1,4,3,5,26,32,1,31,6,3,20,36,13,18,15,7,12,9}

    Returns: 575

  32. " "

    {33,5,15,8,26,13,28,12,24,10,27,19,4,11,11,9,17,28,18,23,10,32,30,35,19,19}

    {33,5,15,8,26,13,28,12,24,10,27,19,4,11,11,9,17,28,18,23,10,32,30,35,19,19}

    Returns: 183

  33. "asdfjrijhirgjrgjroSDFGJOJSOJDOFJSODF"

    {34,8,28,26,14,7,11,7,18,36,21,1,10,35,31,19,9,7,9,27,11,4,34,12,21,11}

    {34,8,28,26,14,7,11,7,18,36,21,1,10,35,31,19,9,7,9,27,11,4,34,12,21,11}

    Returns: 784

  34. "Dead Beef"

    {6, 6, 6, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    {5, 5, 5, 4, 4, 4, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    Returns: 49

  35. "D"

    {6, 6, 6, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    {5, 5, 5, 4, 4, 4, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    Returns: 7

  36. "ThE qUiCk BrOwN fOx JuMpEd OvEr ThE lAzY dOg"

    {36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11 }

    {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 }

    Returns: 778

  37. " "

    {6, 6, 6, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    {5, 5, 5, 4, 4, 4, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    Returns: 43

  38. "Dead Beef "

    {5, 6, 6, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    {5, 6, 6, 6, 5, 6, 6, 6, 5, 6, 6, 6, 6, 6, 5, 6, 6, 6, 6, 6, 5, 6, 6, 6, 6, 6 }

    Returns: 60

  39. " "

    {6, 6, 6, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    {6, 6, 6, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    Returns: 7

  40. "ABCDEFGHIJKLMNOPQRSTUVWYZabcdfghijklmopqrstuvwxyz "

    {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 }

    {26, 25, 24, 23, 22, 21, 20, 18, 16, 14, 12, 11, 10, 9, 8, 6, 7, 5, 4, 3, 2, 1, 13, 15, 17, 19 }

    Returns: 699

  41. " "

    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }

    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }

    Returns: 39

  42. " "

    {6, 6, 6, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    {6, 6, 6, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    Returns: 3

  43. "two spaces between "

    {9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }

    Returns: 87

  44. "ThE qUiCk BrOwN fEzzzd OzzzvEr TZZZ lAzY dOg"

    {36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11 }

    {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 }

    Returns: 790

  45. "ZZZZZ"

    {6, 6, 6, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    {5, 5, 5, 4, 4, 4, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    Returns: 49

  46. "hello world is d u m b"

    {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 }

    {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 }

    Returns: 155

  47. " "

    {6, 6, 6, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    {5, 5, 5, 4, 4, 4, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    Returns: 23

  48. "Aead Beef"

    {6, 6, 6, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    {5, 5, 5, 4, 4, 4, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    Returns: 48

  49. " Hola pola "

    {6, 6, 6, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    {5, 5, 5, 4, 4, 4, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    Returns: 83

  50. "AAAAAAA"

    {9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }

    {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }

    Returns: 69


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: