Microsoft | Onsite | Group by buckets
Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2022-02-04Added By Anonymous
Source: Link
1.Given a large sorted array of keys (Strings);
2.distributes these keys, sorted, across approx 1000 buckets, so that each bucket has about the same number of characters;
3.the requested output is an array of approx 1000 keys that represent, for each bucket, the highest key.
public List<String> groupByBuckets(List<String> keys) {}
1.
1public interface FixedReader {
2 // Reads up to the next 4096 bytes of data from a file and stores
3 // the results in |buffer| at |offset| specified.
4 // Returns the number of bytes read into |buffer|. If the return
5 // value is less than 4096, this indicates that the end of file has
6 // been reached.
7 public int read4K(byte[] buffer);
8}
9
10public class ByteReader {
11 public ByteReader(FixedReader fixedReader) {
12 }
13
14
15 // Read |byteCount| bytes from the stream passed into the
16 // constructor, and store the data in |buffer|. |buffer|
17 // must be allocated by the caller and be at least
18 // |byteCount| bytes long. The return value is the number of
19 // bytes read and stored in |buffer|, and is always
20 // <= |byteCount|. If the return value is < |byteCount|, it
21 // indicates that the end of the file has been reached.
22public int readBytes(byte[] buffer, int byteCount) {}