Statistics

Problem Statement for "SumSort"

Problem Statement

Given an inclusive range of numbers you will first sort them in ascending order by their digit sum (sum of their decimal digits). Ties are settled by the numbers' values, lower numbers first. You will then return the value at location pos (0-based) in the newly sorted list. For example:
rangeLow = 0
rangeHigh = 10
pos = 3
The sorted range is : 0,1,10,2,3,4,5,6,7,8,9. The value at position 3 is 2. Note that 10 comes before 2 since the digit sum of 10 is 1 whereas the digit sum of 2 is 2. Also note that 10 comes after 1 even though they have the same digit sum since 10 is greater than 1.

Definition

Class:
SumSort
Method:
valueAt
Parameters:
int, int, int
Returns:
int
Method signature:
int valueAt(int rangeLow, int rangeHigh, int pos)
(be sure your method is public)

Constraints

  • rangeLow will be between 0 and 1000000000 (10^9) inclusive
  • rangeHigh will be between 0 and 1000000000 (10^9) inclusive
  • rangeLow will be less than or equal to rangeHigh
  • pos will be between 0 and (rangeHigh - rangeLow) inclusive

Examples

  1. 0

    1000000000

    1000000

    Returns: 102721002

  2. 0

    10

    4

    Returns: 3

  3. 100

    200

    5

    Returns: 111

  4. 0

    1000000000

    40

    Returns: 10000010

  5. 0

    1000000000

    999940000

    Returns: 987996896

  6. 1

    999999999

    999940000

    Returns: 987996968

  7. 122033039

    951437403

    396834650

    Returns: 828153652

  8. 938698567

    944819462

    2782727

    Returns: 943431684

  9. 657505331

    860262994

    141169975

    Returns: 827806646

  10. 690391008

    999658823

    215652607

    Returns: 964822953

  11. 217154294

    350239048

    33731615

    Returns: 235718124

  12. 657599257

    948408718

    278295890

    Returns: 892639668

  13. 357533578

    664724268

    14177361

    Returns: 520026921

  14. 465810670

    634077961

    3173080

    Returns: 612533022

  15. 479204754

    497346775

    16047535

    Returns: 480997457

  16. 327447103

    949864909

    36865218

    Returns: 592070402

  17. 415360651

    576905647

    137583604

    Returns: 455803996

  18. 95571846

    621297840

    517986621

    Returns: 294826899

  19. 130354632

    563768072

    412803267

    Returns: 527796637

  20. 802069924

    856627243

    45277604

    Returns: 845293459

  21. 312710916

    954592756

    528288724

    Returns: 918965650

  22. 496381154

    688940060

    33915337

    Returns: 522247930

  23. 993325299

    998711405

    741990

    Returns: 994364161

  24. 566987999

    817707473

    232191578

    Returns: 787347279

  25. 233266041

    397457556

    11579060

    Returns: 375032160

  26. 996021865

    996518950

    488601

    Returns: 996469568

  27. 400014206

    425224461

    9387572

    Returns: 419561025

  28. 215403894

    468087285

    36054956

    Returns: 372004464

  29. 251182392

    368945112

    43963587

    Returns: 328264911

  30. 745604538

    808785743

    19587822

    Returns: 750653663

  31. 557632730

    973502747

    96136758

    Returns: 825509800

  32. 496993050

    692104616

    187430491

    Returns: 528778496

  33. 82269580

    113679772

    21459832

    Returns: 96833336

  34. 187330121

    492357318

    9579893

    Returns: 261040218

  35. 567272702

    755426877

    43142216

    Returns: 654822630

  36. 512584502

    728540684

    81185336

    Returns: 602801598

  37. 823703113

    954702508

    43176937

    Returns: 835551536

  38. 534155728

    619948460

    75173010

    Returns: 583681758

  39. 837668691

    901989615

    48462812

    Returns: 888086184

  40. 792860654

    841473526

    41151482

    Returns: 793551687

  41. 952870260

    990373551

    18849908

    Returns: 985912049

  42. 304667804

    588295037

    182414904

    Returns: 426129829

  43. 28525449

    670303136

    489823411

    Returns: 370775817

  44. 257993467

    691085749

    148843620

    Returns: 508776310

  45. 44425151

    362371026

    173341204

    Returns: 358163426

  46. 637130907

    759457534

    118080260

    Returns: 678578565

  47. 893130347

    963179508

    10442430

    Returns: 942441623

  48. 407674283

    630648290

    53065150

    Returns: 423028826

  49. 196855842

    988990594

    303097732

    Returns: 459034419

  50. 381094927

    700137148

    83563509

    Returns: 482588010

  51. 469073410

    856963082

    282625128

    Returns: 699680081

  52. 537282722

    637999158

    8692835

    Returns: 632105913

  53. 35841939

    895327870

    51810442

    Returns: 440608122

  54. 833107234

    995871017

    3701563

    Returns: 944205500

  55. 988748148

    996685899

    2391663

    Returns: 990274572

  56. 315979812

    733954856

    132661287

    Returns: 406944361

  57. 0

    10

    3

    Returns: 2

    This is the example above

  58. 78

    93

    13

    Returns: 79

    The numbers are sorted as: 80, 81, 90, 82, 91, 83, 92, 84, 93, 85, 86, 78, 87, 79, 88, 89

  59. 2167

    2843

    52

    Returns: 2520


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: