**Apple Interview [REJECT]**

**

Year of Exp:- 12**

**1st Phone:-**

Design a data structure that storeskey value pair and returns value based on time and key. I was asked to write two api put(Key,value) anda get(key,timestamp);

```
for exmple
t=0;
put("1", 1);
```

t=5

put ("1", 5)

get("1",t=2) return 1;

```
Solution --> I created a map with key and value is heapmap based on time stamps and value.
```

**2nd Round Phone**

You have a big file with lots of rows each, and row contains a range and a float number, you have to save them in database. Also when asked return float based on a number which is in the range. For exp

0 100 1.2

100 200 3.2

200 900 5.2

Now write a query to get float value for number N where number will be in given range.

example if N=10 return 1.2

if N=110 return 3.2

Created Table with start and end and value. I asked if there could be multiple files and do I need to normalize the data if there are multiple files.

Follow up

How will I store this in memory?

Solution:- Stored it in triplet and perform a binary search to get the corresponding value.

Onsite

**1st Round**

You have 1 row chess game in which, Whites are moving forward and Black are coming backward. You are given two position arrays of start/end indexes of whites and black. You have to tell if it is possible to go from start to end pos. The only restriction is, W and B can’t cross each other. Basically find overlapping interval between white and back.

```
[,W,,W,,,,B] Start pos W==> [1,3] End Pos White [4,6]
[,,,W,B,W,,] Start Pos black==> [7] End Pos Black [5]
Result false as W at 4 will head on with black at 7.
I started with a sorted map and tried to find any intersection between white and black. Interviewer wasn’t happy, immediately after the interview, I realized this could have solved in O(N) by sweep line. But it was too late.
```

**Round 2 **

General question on OOPS and project specific.

One easy coding question on encoding string. For a given string encode it by moving each character by two places. For ex AC B->D and ZB.

easy one

**Round 3**

Give an array of Byte and an index you have to tell of it is part of two letter word or 1 letter word.

A Byte is a two letter word if its MSB is 1 or else 1. If it is a two letter word then it will span over next index and both will be two letter word. For exp.

[10000000, 00000000]

For given array index 0 and index 1 bother are two letter word.

Easy one.

**Round 4**

I was asked to write below API’s to store VIN based on make, model, and color, where put can suffer in performance but get should be real fast.

void Put(Make, Model,Color, VIN)

String[] get(make,model,color) all VIN matching criteria.

I proposed two solution Hash map or Trie and implemented Trie solution.

Follow up, how would I support null in get. For exp. (null, null, blue) should return me VIN of all blue cars added into my structure.

Proposed one null node at each level and when put called, modify nodes at two places (null entry and matching entry.)

Good one

**Round 5** Implement API rate limiter, no more than 10 request each second.

Easy one.

**Round 6**

You are given an array of integer and a number n, print all the number less then given number when formed using a given array.

For exp ([1,2,3], 100)

print

1,2,3,12,21,23,31.

Wrote recursive solution to generate all permutation, if permutation goes above the number just return;

Result Rejected.