Statistics

Problem Statement for "Stream"

Problem Statement

Write a method which breaks up a stream of bits into chunks of some given length, converts each chunk into an integer, and returns an array of integers that represents these chunks. The stream is represented by an array of integers. Each integer's binary equivalent represents a 32 bit portion of the stream.

If the stream cannot be divided into chunks of equal length, then pad the end of the stream with zeros until chunks of equal length can be obtained.

Definition

Class:
Stream
Method:
breakup
Parameters:
int[], int
Returns:
int[]
Method signature:
int[] breakup(int[] stream, int size)
(be sure your method is public)

Constraints

  • stream contains between 1 and 4 elements, inclusive.
  • Each element of stream is between 0 and 2147483647, inclusive.
  • size is between 1 and 32, inclusive.

Examples

  1. {512, 1024, 2048, 4096}

    16

    Returns: { 0, 512, 0, 1024, 0, 2048, 0, 4096 }

  2. {2096545431}

    5

    Returns: { 15, 19, 27, 11, 29, 5, 24 }

  3. {511, 255, 63, 31}

    8

    Returns: { 0, 0, 1, 255, 0, 0, 0, 255, 0, 0, 0, 63, 0, 0, 0, 31 }

  4. {456, 235, 356, 234}

    19

    Returns: { 0, 29184, 1, 438272, 178, 0, 7488 }

  5. {111111111, 222222222, 100000, 64}

    29

    Returns: { 13888888, 473234270, 117440707, 167772160, 8388608 }

  6. {1, 2, 3, 4}

    32

    Returns: { 1, 2, 3, 4 }

  7. {32, 255}

    4

    Returns: { 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 15, 15 }

  8. {8191}

    13

    Returns: { 0, 127, 8064 }

  9. {34, 54, 65, 65}

    9

    Returns: { 0, 0, 1, 32, 0, 0, 27, 0, 0, 1, 8, 0, 0, 16, 128 }

  10. {65345656}

    1

    Returns: { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 }

  11. {4}

    31

    Returns: { 2, 0 }

  12. {67567, 5678, 76756}

    17

    Returns: { 2, 8124, 0, 90848, 37, 62720 }

  13. {2147483647}

    32

    Returns: { 2147483647 }

  14. {1, 2}

    5

    Returns: { 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 4 }

  15. {2147483637}

    5

    Returns: { 15, 31, 31, 31, 31, 29, 8 }

  16. {999999999, 999999999, 999999999, 999999999}

    32

    Returns: { 999999999, 999999999, 999999999, 999999999 }

  17. {4, 3}

    10

    Returns: { 0, 0, 1, 0, 0, 0, 192 }

  18. {2147483647, 2147483647, 2147483647}

    5

    Returns: { 15, 31, 31, 31, 31, 31, 27, 31, 31, 31, 31, 31, 30, 31, 31, 31, 31, 31, 31, 16 }

  19. {8191}

    13

    Returns: { 0, 127, 8064 }

  20. {1, 2, 3}

    3

    Returns: { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3 }

  21. {511, 255, 63, 31}

    8

    Returns: { 0, 0, 1, 255, 0, 0, 0, 255, 0, 0, 0, 63, 0, 0, 0, 31 }

  22. {8191}

    13

    Returns: { 0, 127, 8064 }

  23. {255}

    10

    Returns: { 0, 0, 63, 768 }

  24. {2147483647, 2147483647, 89, 12345}

    9

    Returns: { 255, 511, 511, 503, 511, 511, 511, 256, 0, 1, 200, 0, 6, 14, 128 }

  25. {8191}

    13

    Returns: { 0, 127, 8064 }

  26. {578383745, 2342344, 2344433, 2356454}

    23

    Returns: { 1129655, 6307848, 7846144, 146527, 524575, 5478400 }

  27. {0, 1, 0, 1}

    2

    Returns: { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }

  28. {1001001, 101110, 111}

    11

    Returns: { 0, 977, 1106, 0, 197, 984, 0, 0, 888 }

  29. {32}

    32

    Returns: { 32 }

  30. {0}

    1

    Returns: { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }

  31. {0, 123456789, 987654321, 65355}

    31

    Returns: { 0, 30864197, 660327702, 268439540, 1476395008 }

  32. {0, 1, 1, 0}

    1

    Returns: { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }

  33. {32,255}

    4

    Returns: { 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 15, 15 }

    32 is 255 is 00000000000000000000000000100000 00000000000000000000000011111111 Breaking it down to chunks of 4 bits in length yields: 0000 0000 0000 0000 0000 0000 0010 0000 0000 0000 0000 0000 0000 0000 1111 1111 0 0 0 0 0 0 2 0 0 0 0 0 0 0 15 15

  34. {8191}

    13

    Returns: { 0, 127, 8064 }

    8191 padding 00000000000000000001111111111111 0000000 0000000000000 0000001111111 1111110000000 0 127 8064 Notice that without the padding the stream could not have been divided into chunks of 13 bits.

  35. {34}

    32

    Returns: { 34 }

  36. {1}

    1

    Returns: UNKNOWN-OUTPUT10291821323

  37. {511, 255, 63, 31}

    8

    Returns: { 0, 0, 1, 255, 0, 0, 0, 255, 0, 0, 0, 63, 0, 0, 0, 31 }


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: