Question: [OFFER] Apple | SDE-1 | On Campus | Interview Experience
2
Entering edit mode

Interview Experience - 1 | Selected


Round - 1

  • Introduce yourself.
  • Jumped straight to programming problem.
    Given a M x N grid map, each cell of grid is '1' if there 
    is land, '0' if there is water. Print number of Islands.
    
    An island is surrounded by water and is formed by connecting adjacent lands (vertically or horizontally). You can assume outside matrix is completely filled with water.
  • Resume based questions.
  • OOPS.
  • Real life Example for binary search.
  • CN Questions
    • ipv4 vs ipv6
    • LAN vs WAN
    • Switch
    • Router
    • OSI Layers
  • Some OS questions.
  • What are micro services? ( context : from resume)
  • General vision on computer science.
  • General discussion on security.
  • What interests you most in Computer Science and Why?
  • Do u have any questions for me?

  • Round 2

    • Introduce yourself.
    • DBMS - Normal forms, foreign keys, PostgreSQL - advantages
    • Resume projects - grilled through CV
      - For each project they ask u more in detail and ask for different scenarios and corner cases in 2nd round, for me only one btp
    • project was grilled for almost 35 min.
      - Regarding system stability, approaches tried, what is the most complex part in the whole project, why u chose this approach, why not other approaches etc
    • What is mvc architecture?
    • General behavioural questions.
      • Given 2 roles, what do you choose why?
      • What are your goals in future?
      • Why apple?
      • Do u have any other dream companies?
      • Are you interested in devops?
      • Do you have any other questions to ask?

    Round - 3 (HR)

    • Introduce yourself.
    • How have you taken decisions in your life till now? (Eg. Why Engineering? , Why CSE?, Why IIIT Hyderabad?, Is it peer pressure ?)
    • Given a situation where u and ur colleague's ideas are equally important and valid. What would you choose? Why?
    • Why Apple?
    • What are your strengths and weaknesses? Do ur friends agree that ur opinion matches with them?
    • Do you have any questions?

    SELECTED

ADD COMMENTlink 4.3 years ago mod2 870
3
Entering edit mode
I'll discuss solution to the coding problem from Round 1, if you want to know answer to any other question, simply comment.

Solution

We can treat given grid as an , assuming each grid cell is a node, and two nodes are connected if both of them are land and adjacent in grid.

Now required answer is simply in our graph. We can do it by using DFS, BFS or DSU (Disjoint Set Union) and time complexity remains in each cases.

99% of people end up using DFS, however most for this question is BFS and reason is it has best space complexity!

SolutionTime ComplexitySpace Complexity
DFSO(N x M)O(N x M)
BFSO(N x M)O(min(N, M))
DSUO(N x M)O(N x M)


BFS Solution

Space Complexity proof

A picture is worth thousand words!This shows time complexity is clearly O(min(N, M)) which is better than DFS and DSU.
Imagine you telling this in the Apple interview!
  int solve(vector>& grid) {
    int nr = grid.size();
    if (!nr) return 0;
    int nc = grid[0].size();

    int num_islands = 0;
    for (int r = 0; r < nr; ++r) {
      for (int c = 0; c < nc; ++c) {
        if (grid[r][c] == '1') {
          ++num_islands;
          grid[r][c] = '0'; // mark as visited
          queue> neighbors;
          neighbors.push({r, c});
          while (!neighbors.empty()) {
            auto rc = neighbors.front();
            neighbors.pop();
            int row = rc.first, col = rc.second;
            if (row - 1 >= 0 && grid[row-1][col] == '1') {
              neighbors.push({row-1, col}); grid[row-1][col] = '0';
            }
            if (row + 1 < nr && grid[row+1][col] == '1') {
              neighbors.push({row+1, col}); grid[row+1][col] = '0';
            }
            if (col - 1 >= 0 && grid[row][col-1] == '1') {
              neighbors.push({row, col-1}); grid[row][col-1] = '0';
            }
            if (col + 1 < nc && grid[row][col+1] == '1') {
              neighbors.push({row, col+1}); grid[row][col+1] = '0';
            }
          }
        }
      }
    }

    return num_islands;
  }
ADD COMMENTlink 4.3 years ago admin 1.6k
Entering edit mode
1

This is not correct. The space complexity should also take into account the space used for input values (the grid in this case), and hence the space complexity will still be O(N * M).

ADD REPLYlink 2.3 years ago
Tanish Lad
• 20
Entering edit mode
2

When algorithms/solutions are being compared, it makes sense to compare them by space/time taken by the algorithm/solution itself. Thus, in interview setting when we say space complexity it defaults to improving Auxilary space complexity (helps compare solutions proposed by multiple people). Auxilary space complexity doesn't care about input taken by space.

ADD REPLYlink 2.3 years ago
admin
1.6k
Entering edit mode
0

I believe that when we talk about "Space Complexity", it means the auxiliary space plus the space for input. So it is technically not correct to mention "Space Complexity" as O(min(N, M)) because it is still O(N * M). That being said, it definitely gives a better impression if you clarify that the "Auxiliary space" taken by my algorithm is just O(min(N, M)) and compare it with the "Auxiliary space" taken by other algorithms.

ADD REPLYlink 2.3 years ago
Tanish Lad
• 20
Entering edit mode
1

It's always helpful to clarify when you speak & be technically appropriate, agreed 100%. The original idea still stands true. If you look at solutions provided to interviewers at Google, Microsoft, etc - they mean "auxiliary" but referred to it as Space complexity - re-enforcing bias in the industry.

ADD REPLYlink 2.3 years ago
admin
1.6k
Entering edit mode
0

Hey I have a few questions if you can answer them it would be great:
1. Which university or college are you from?
2. What was the ctc offered to you?

ADD REPLYlink 7 months ago
Snehil Saini
• 0

Login before adding your answer.

Similar Posts
Loading Similar Posts