Preparing for an interview? Check out Cracking the Coding Interview
Published on

Google | L5 | Round 1

Author
  • Shared Anonymously

Problem Statement
You are given a file represented as an array of bytes (byte[] arr). Each byte in this array can have a prefix that determines the number of subsequent bytes that together form a useful number. The prefix sizes range from 1 byte to 8 bytes. You need to extract these useful numbers from the byte array without exceeding a given byte limit (k).

Input
A byte array byte[] arr which represents the file containing useful numbers with prefixes.
An integer int k which specifies the maximum number of bytes that can be used.
Output
Return an array of integers that represents the useful numbers extracted from the byte array without exceeding the byte limit k.

Constraints
The prefix size is encoded in the first 4 bits of each byte. The prefix size indicates the number of bytes that make up the useful number.
You should stop processing if adding the next number exceeds the byte limit k.
Array can be very long like 1 millian records.

Sinature FYI

public int[] cutArray(byte[] arr, int k)  

Verdict: The problem was too ambiguous that the interviewer couldn't explain it well also I couldn't understand as well. Reject

ReportMark as Helpful