Statistics

Problem Statement for "VideoEncode"

Problem Statement

You would like to compress a video file to fit within a specified file size. You are given the length of the video formatted as "HH:MM:SS" (quotes for clarity only), where HH, MM and SS are two-digit numbers specifying the number of hours, minutes and seconds, respectively. You are also given the desired file size in megabytes. Return the maximum bitrate in kbps (kilobits per second) at which you can encode the video without exceeding the desired size. Please refer to the notes for information on conversion between different units.

Definition

Class:
VideoEncode
Method:
bitrate
Parameters:
String, int
Returns:
double
Method signature:
double bitrate(String length, int desiredSize)
(be sure your method is public)

Notes

  • The return value must have absolute or relative accuracy within 1e-9.
  • One megabyte is equivalent to 1,048,576 bytes.
  • One byte is equivalent to 8 bits.
  • One kilobit is equivalent to 1,000 bits.

Constraints

  • length is formatted as "HH:MM:SS", where HH is a two-digit integer between 00 and 20, inclusive, MM is a two-digit integer between 00 and 59, inclusive, and SS is a two-digit integer between 00 and 59, inclusive.
  • desiredSize is between 50 and 8000, inclusive.
  • length will represent a time of at least 1 second.

Examples

  1. "00:00:01"

    50

    Returns: 419430.4

    This video is 1 second long. To fit into a 50 megabyte file, it must be encoded at 419430.4 kbps. 50 megabytes is equivalent to 419430.4 kilobits.

  2. "20:59:59"

    8000

    Returns: 887.695128242437

  3. "02:00:00"

    4000

    Returns: 4660.337777777778

  4. "20:59:59"

    50

    Returns: 5.548094551515232

  5. "00:00:01"

    8000

    Returns: 6.7108864E7

  6. "08:58:12"

    3208

    Returns: 833.353600396383

  7. "00:42:56"

    4930

    Returns: 16054.284720496895

  8. "10:23:39"

    2243

    Returns: 502.8367338517865

  9. "04:39:24"

    6376

    Returns: 3190.513278931043

  10. "15:21:41"

    3979

    Returns: 603.574460353339

  11. "14:21:46"

    4307

    Returns: 698.7532328163076

  12. "18:02:05"

    4802

    Returns: 620.440440754717

  13. "14:56:48"

    6249

    Returns: 974.2122247992863

  14. "13:45:20"

    50

    Returns: 8.469919224555735

  15. "17:36:08"

    6335

    Returns: 838.6225173589194

  16. "05:17:19"

    6091

    Returns: 2683.7024700877146

  17. "05:23:34"

    1583

    Returns: 683.9995088080766

  18. "09:07:03"

    5531

    Returns: 1413.563380800049

  19. "18:49:06"

    3184

    Returns: 394.25689888701913

  20. "15:11:36"

    6874

    Returns: 1054.2506105016819

  21. "05:45:08"

    6930

    Returns: 2807.2751323160132

  22. "02:45:57"

    755

    Returns: 636.0750266144421

  23. "09:18:03"

    2251

    Returns: 563.9505602245916

  24. "19:35:34"

    6420

    Returns: 763.5305435676412

  25. "20:00:47"

    7542

    Returns: 878.1334619900898

  26. "20:45:21"

    7453

    Returns: 836.7165244576491

  27. "08:52:10"

    5176

    Returns: 1359.8319764484809

  28. "03:01:42"

    6209

    Returns: 4777.551556778572

  29. "00:43:40"

    1805

    Returns: 5779.174595419848

  30. "20:17:35"

    2731

    Returns: 313.58960301142974

  31. "04:11:47"

    4846

    Returns: 2690.8846473820086

  32. "08:53:17"

    2727

    Returns: 714.9337130355971

  33. "08:49:21"

    270

    Returns: 71.31148767356191

  34. "07:27:15"

    1021

    Returns: 319.1641053847587

  35. "00:21:26"

    7997

    Returns: 52164.61755520996

  36. "20:33:35"

    7296

    Returns: 826.9037893399986

  37. "20:40:34"

    3432

    Returns: 386.78161399360505

  38. "20:11:22"

    3804

    Returns: 439.03944349357477

  39. "04:54:17"

    1699

    Returns: 807.1725090332445

  40. "20:56:40"

    7460

    Returns: 829.9604201591512

  41. "20:48:41"

    5496

    Returns: 615.3653791059917

  42. "06:21:24"

    4575

    Returns: 1677.0617724174097

  43. "01:55:21"

    727

    Returns: 881.1613951741077

  44. "20:04:56"

    2450

    Returns: 284.2769945778466

  45. "01:21:34"

    6247

    Returns: 10707.730726604006

  46. "13:32:04"

    4733

    Returns: 814.8608830145308

  47. "13:31:21"

    6755

    Returns: 1164.0074575296317

  48. "19:03:06"

    1367

    Returns: 167.19486682413321

  49. "20:48:06"

    1390

    Returns: 155.7055406885132

  50. "06:52:58"

    3592

    Returns: 1216.0739339736863

  51. "16:05:34"

    554

    Returns: 80.21695087513378

  52. "20:09:34"

    1547

    Returns: 178.81302637308127

  53. "20:47:28"

    688

    Returns: 77.10776913210775

  54. "04:02:37"

    7545

    Returns: 4347.8771285292305


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: