Wednesday, October 28, 2026
HomeArtificial Intelligence10 Frequent Apple Interview Questions

10 Frequent Apple Interview Questions

[ad_1]

apple interview questions

As you would possibly already know, not simply tech positions however a number of different positions are supplied by Apple, comparable to operations, administrative, and so on. and every submit has its personal separate set of interview questions. As we speak, we’re going to focus on the vital Apple interview questions which can be requested in the course of the interview for a technical submit.  

Interview at a Look

All the interview means of Apple for a Software program Engineer or different technical submit candidate could be divided into 3 phases:

  • Pre-screening with the Recruiter
  • Technical Telephonic Interview
  • On-site Interview

The pre-screen with a recruiter can take round one week. A recruiter will arrange an acceptable time for a cellphone name through LinkedIn or e-mail. This cellphone display shall be someplace between 15-Half-hour lengthy and the technicality of the questions won’t be gentle. Some fundamental questions could possibly be questions like, which one is your favourite Apple services or products and why? What drives you to work for and be part of Apple? 

Your subsequent technical cellphone interview is more likely to be scheduled after per week. There shall be one or two technical telephonic interviews. These will include questions on your resume and a coding query on information constructions and algorithms. Every coding cellphone display lasts for about 45-60 minutes, the place Half-hour are assigned for finishing the problem.

The final stage is an on-site interview which is 6 hours lengthy and also you get to fulfill 8-12 staff of Apple. This half contains behavioral evaluation, area data check, and coding challenges the place every interview lasts as much as 45 minutes to 1 hour.  

apple interview questions

Apple Interview Questions

Array and Graph Associated Questions

  1. You might be given a listing (an array) of interval pairs as enter. Every interval has a begin and finish timestamp and is sorted by beginning timestamps. Now, it’s important to merge the overlapping time intervals and return a brand new output array. How will you do it?

For Instance: For a listing of pairs of timestamps (2, 6), (4, 9), (10, 14), (12, 16), the output must be (2, 9), (10, 16)

You should utilize a linear scan algorithm to unravel this downside assertion. The checklist of enter timestamps is given, and the output checklist could have the merged lists. You will notice if, for every interval within the enter checklist, the final interval of the output checklist overlaps with the interval within the enter checklist merging the 2 intervals. Additional, substitute the final interval of the output checklist with the newly merged interval.

Else, merely add the enter interval to the output checklist. The code for a similar in C++ could be as follows:

#embody <iostream>
#embody <vector>

utilizing namespace std;

class Pair{
  public:
    int first, second;
    Pair(int x, int y){
      first = x;
      second = y; 
    }
};

vector<Pair> merge_intervals(vector<Pair>& v) {

  if(v.measurement() == 0) {
    return v;
  }

  vector<Pair> end result;
  end result.push_back(Pair(v[0].first, v[0].second));

  for(int i = 1 ; i < v.measurement(); i++){
    int x1 = v[i].first;
    int y1 = v[i].second;
    int x2 = end result[result.size() - 1].first;
    int y2 = end result[result.size() - 1].second;

    if(y2 >= x1){
      end result[result.size() - 1].second = max(y1, y2);
    }
    else{
      end result.push_back(Pair(x1, y1));
    }
  }
  return end result;
}

int most important() {
  vector<Pair> v {
                  Pair(2, 6),
                  Pair(4, 9),
                  Pair(10, 14),
                  Pair(12, 16),
                 Pair(18, 22)
                  };

  vector<Pair> end result = merge_intervals(v);
  
  for(int i = 0; i < end result.measurement(); i++){
    cout << "[" << result[i].first << ", " << end result[i].second << "] ";
  }
}

Output

apple interview questions
  1. Write the code to find out if there are any three integers within the given array of integers which can be equal to a given worth.

So as to resolve this downside assertion, first, type information within the array. Then, repair one array aspect okay and discover a pair (a, b) from the remaining array such that given_value-k=a+b. 

Begin by fixing the primary aspect (okay) of the array, then seek for a pair (a, b) within the remaining array, i.e. from aspect arr[1] to arr[n-1] that meets the situation, given_value-k=a+b. If you happen to discover such a pair with the primary aspect okay that collectively makes a sum equal to the given worth, no additional iteration is required. Else, you’ll repeat the above steps for all of the okay components from arr[1] to arr[n-3] till an identical sum is discovered.

The code for a similar in C++ could be as follows: 

#embody <iostream>
#embody <vector>
#embody <bits/stdc++.h>

utilizing namespace std;

bool sum_two(vector<int>& m, int worth, size_t begin ) {
    for (int i = begin, j = m.measurement() - 1; i < j;) {
    int sum1 = m[i] + m[j];
    if (sum1 == worth) {
      return true;
    }

    if (sum1 < worth) {
      ++i;
    } else {
      --j;
    }
  }

  return false;
}

bool sum_three_v3(vector<int> arr, int given_value) {

std::type(arr.start(), arr.finish());

for (int i = 0; i < arr.measurement() - 2; ++i) {
  int remaining_sum = given_value - arr[i];
  if (sum_two(arr, remaining_sum, i + 1)) {
      return true;
    }
  }

  return false;
}

int most important(){
         //For a given array: {27, -12, 36, -5, -15, 4, 6, 8}
         vector<int> arr = {27, -12, 36, -5, -15, 4, 6, 8};
         cout<<"18: " <<sum_three_v3(arr, 18)<<endl;
         cout<<"18: " <<sum_three_v3(arr, 1)<<endl;
         return 0;
     }

Output

apple interview questions
  1. You’ll be given the basis node of a directed graph and you’ll have to clone the graph by making a deep copy. The cloned graph is meant to have the identical edges in addition to vertices.

We use depth-first traversal and create a duplicate of every node as we carry out traversal of the graph. We’ll use a hash desk to retailer each accomplished node so we won’t must revisit nodes saved in that hash desk. The hash desk key will maintain a node of the unique graph. So, its worth would be the corresponding node within the cloned graph.

#embody <iostream>
#embody <vector>
#embody <bits/stdc++.h>


utilizing namespace std;

struct Node {
  int information;
  checklist<Node*> neighbors;
  Node(int d) : information(d) {}
};

Node* clone_rec(Node* root, 
        unordered_map<Node*, 
        Node*>& nodes_comp) {
  
  if (root == nullptr) {
    return nullptr;
  }

  Node* pNew = new Node(root->information);
  nodes_comp[root] = pNew;
  
  for (Node* p : root->neighbors) {
    
    auto x = nodes_comp.discover(p);
    
    if (x == nodes_comp.finish()){
      pNew->neighbors.push_back(clone_rec(p, nodes_comp));
    } else {
      pNew->neighbors.push_back(x->second /*worth*/);
    }
  }
  
  return pNew;
}

Node* clone(Node* root) {
  unordered_map<Node*, Node*> nodes_comp;
  return clone_rec(root, nodes_comp);
}

/*that is un-directed graph i.e. if there exists an edge from node1 to node2, there have to be an edge from node2 to x
node1. And, there isn't a self directing edge to a node. So, the utmost variety of edges that may exist within the graph is: (nodes * nodes - nodes) / 2 */

void create_test_graph_undirected(int nodes, int edges, vector<Node*>& vertices) {
  for (int i = 0; i < nodes; ++i) {
    vertices.push_back(new Node(i));
  }

  vector<pair<int, int>> all_edges;
  for (int i = 0; i < vertices.measurement(); ++i) {
    for (int j = i + 1; j < vertices.measurement(); ++j) {
      all_edges.push_back(pair<int, int>(i, j));
    }

  }

  std::random_shuffle(all_edges.start(), all_edges.finish());

  for (int i = 0; i < edges && i < all_edges.measurement(); ++i) {
    pair<int, int>& edge = all_edges[i];
    vertices[edge.first]->neighbors.push_back(vertices[edge.second]);
    vertices[edge.second]->neighbors.push_back(vertices[edge.first]);
  }
}

void print_graph(vector<Node*>& vertices) {
  for (Node* n : vertices) {
    cout << n->information << ": {";
    for (Node* t : n->neighbors) {
      cout << t->information << " ";
    }
    cout << "}" << endl;
  }
}

void print_graph(Node* root, unordered_set<Node*>& visited_nodes) {
  if (root == nullptr || visited_nodes.discover(root) != visited_nodes.finish()) {
    return;
  }

  visited_nodes.insert(root);

  cout << root->information << ": {";
  for (Node* n : root->neighbors) {
    cout << n->information << " ";
  }
  cout << "}" << endl;
  for (Node* n : root->neighbors) {
    print_graph(n, visited_nodes);
  }
}

void print_graph(Node* root) {
  unordered_set<Node*> visited_nodes;
  print_graph(root, visited_nodes);
}

int most important() {
  vector<Node*> vertices;
  create_test_graph_undirected(7, 18, vertices);
  
  print_graph(vertices[0]);

  Node* cp = clone(vertices[0]);
  cout << endl << "After copy" << endl;
  print_graph(cp);
  
  return 0;
}
apple interview questions

Tree-Based mostly Questions

  1. You may have the roots of two binary timber and it’s important to decide if these binary timber are equivalent, i.e., each the timber have the very same construction and aspect at every node.

We will use recursion to unravel this downside by which the bottom case could be if two in contrast nodes give null or any one in every of them is null.

We suppose the given binary timber are A and B respectively. Pertaining to those two timber being equivalent, there are three potentialities:

  • The basis aspect of A and B is identical or each roots of A and B are null
  • The l subtrees of A and B are equivalent.
  • The r subtrees of A and B are equivalent.

We carry on evaluating the weather at every degree of each the timber utilizing a depth-first traversal on each timber on the similar time.

bool check_identical(
  BinaryTreeNode* root1,
  BinaryTreeNode* root2) {

  if (root1 == nullptr && root2 == nullptr) {
    return true;
  }
  
  if (root1 != nullptr && root2 != nullptr) {
    return ((root1->information == root2->information) &&
            check_identical(root1->l, root2->l) &&
            check_identical(root1->r, root2->r));
  }

  return false;
}

int most important() {
  BinaryTreeNode *root1 = new BinaryTreeNode(100);
  insert_bst(root1, 50);
  insert_bst(root1, 200);
  insert_bst(root1, 25);
  insert_bst(root1, 125);
  insert_bst(root1, 350);

  display_level_order(root1);
  
  BinaryTreeNode *root2 = create_random_BST(15);

  display_level_order(root2);
  
  // Test by altering the roots handed
  if(check_identical(root1, root2)) {
    cout<< " the timber are equivalent" << endl;
  } else {
    cout<< "the timber will not be equivalent" << endl;
  }
}

Output

apple interview questions
  1. How would you establish whether or not the r and l sub-trees in a given binary tree are mirror photographs?

We will resolve this downside assertion by writing a recursive operate that may take two timber as an argument, and verify recursively two roots and sub-trees underneath the basis. It is going to return true if l and r sub-trees are the mirror and false if timber will not be mirrored. 

Two timber are mirror photographs of one another provided that the next circumstances flip true:

  • Their root node’s key have to be the identical 
  • l sub-tree of l tree and r sub-tree of r tree must be mirror photographs
  • r sub-tree of l tree and l sub-tree of r tree must be mirror photographs

Its code implementation in C++ could be as follows:

#embody <bits/stdc++.h>
utilizing namespace std;
  
// A construction for Binary Tree Node
struct Node 
{
    int key;
    struct Node *l, *r;
};
  
// For creation of latest Node
Node* newNode(int key)
{
    Node* temp = new Node;
    temp->key = key;
    temp->l = temp->r = NULL;
    return (temp);
}
  
//Checks if root1 and root2 mirror
bool is_mirror(struct Node* root1, struct Node* root2)
{
        if (root1 == NULL && root2 == NULL)
        return true;
  
    if (root1 && root2 && root1->key == root2->key)
        return is_mirror(root1->l, root2->r)
               && is_mirror(root1->r, root2->l);
  
        return false;
}
  
//Checks if tree is symmetric
bool is_Symmetric(struct Node* root)
{
        return is_mirror(root, root);
}
  
int most important()
{
    // Assemble a tree as per your individual accord
    Node* root = newNode(1);
    root->l = newNode(2);
    root->r = newNode(2);
    root->l->l = newNode(3);
    root->l->r = newNode(4);
    root->r->l = newNode(4);
    root->r->r = newNode(3);
  
    if(is_Symmetric(root))
      cout<<"Symmetric";
    else
      cout<<"Not symmetric"; 
    return 0;
}

Output

apple interview questions

Linked-Record Based mostly Questions

  1. You might be requested so as to add two integers utilizing linked lists. The top of the 2 linked lists is given and every node shops a digit of the integer. You need to create a brand new linked checklist that shops the sum of two integers. 

For simplification, you’ll be able to retailer the integers inverted within the linked lists, i.e., essentially the most vital digit of the quantity is saved within the final node of the linked checklist. Now to start out including, begin from the heads of the 2 linked lists. With every iteration, the digits on the present nodes of the 2 lists are added and the sum is saved in a brand new node on the tail of the result-linked checklist. So, be sure to take care of carry for every step, if any. On this approach, you proceed for all digits and create the resultant linked checklist. If one of many two lists finishes earlier, proceed with the opposite checklist and remaining carry.

utilizing namespace std;
//assuming each integers are saved in a linked checklist instance, 415 is saved as 5->1->4
LinkedListNode* add_integers(
    LinkedListNode* integer1, 
    LinkedListNode* integer2) {

  LinkedListNode* end result = nullptr;
  LinkedListNode* final = nullptr;
  int carry = 0;
  
  whereas (
      integer1 != nullptr ||
      integer2 != nullptr ||
      carry > 0) {

    int first = 
        (integer1 == nullptr ? 0 : integer1->information);
    int second = 
        (integer2 == nullptr ? 0 : integer2->information);

    int sum = first + second + carry;

    LinkedListNode* pNew = 
          new LinkedListNode(sum % 10);
    
    carry = sum / 10;

    if (end result == nullptr) {
      end result = pNew;
    } else {
      last->subsequent = pNew;
    }

    final = pNew;
    
    if (integer1 != nullptr) {
      integer1 = integer1->subsequent;
    }
    
    if (integer2 != nullptr) {
      integer2 = integer2->subsequent;
    }
  }
  
  return end result;
}

int most important(int argc, char* argv[]) {
	vector<int> v1 = {1, 2, 3}; // 321
  vector<int> v2 = {1, 2}; // 21
  
  LinkedListNode* first = LinkedList::create_linked_list(v1);
  LinkedListNode* second = LinkedList::create_linked_list(v2);

  // sum must be 321 + 21 = 342 => 2->4->3
  LinkedListNode* end result = add_integers(first, second);
  vector<int> r = {2, 4, 3}; // 342
  LinkedListNode* anticipated = LinkedList::create_linked_list(r);
  assert(LinkedList::is_equal(end result, anticipated));

  cout << endl << "First:";
  LinkedList::show(first);
  cout << endl << "Second:";
  LinkedList::show(second);
  cout << endl << "Consequence:";
  LinkedList::show(end result);

  end result = add_integers(first, nullptr);
  assert(LinkedList::is_equal(end result, first));

  end result = add_integers(nullptr, second);
  assert(LinkedList::is_equal(end result, second));
}

Output

apple interview questions
  1. Two sorted linked lists are given and you want to merge these linked lists in a approach that the ensuing linked checklist can be sorted.

Keep a head and a tail pointer on the resultant merged linked checklist and the merged linked checklist shall be NULL initially. Select the top of the merged linked checklist by evaluating the primary node of each linked lists.

Evaluate and decide the smaller present node and hyperlink it to the tail of the resultant for all the following nodes within the two linked lists. Transfer the present pointer of the resultant checklist to the subsequent node. If one of many two linked lists finishes sooner, hyperlink the remaining checklist to the tail of the merged checklist. 

utilizing namespace std;

typedef LinkedListNode* NodePtr;

NodePtr merge_sorted(NodePtr head1, NodePtr head2) {
  
  // if each lists are empty then merged checklist can be empty
  // if one of many lists is empty then different is the merged checklist
  if (head1 == nullptr) {
    return head2;
  } else if (head2 == nullptr) {
    return head1;
  }

  NodePtr mergedHead = nullptr;
  if (head1->information <= head2->information) {
    mergedHead = head1;
    head1 = head1->subsequent;
  } else {
    mergedHead = head2;
    head2 = head2->subsequent;
  }

  NodePtr mergedTail = mergedHead;
  
  whereas (head1 != nullptr && head2 != nullptr) {
    NodePtr temp = nullptr;
    if (head1->information <= head2->information) {
      temp = head1;
      head1 = head1->subsequent;
    } else {
      temp = head2;
      head2 = head2->subsequent;
    }

    mergedTail->subsequent = temp;
    mergedTail = temp;
  }

  if (head1 != nullptr) {
    mergedTail->subsequent = head1;
  } else if (head2 != nullptr) {
    mergedTail->subsequent = head2;
  }

  return mergedHead;
}

void check(vector<int>& v1, vector<int>& v2, vector<int>& anticipated) {
  LinkedListNode* list_head1 = LinkedList::create_linked_list(v1);
  
  cout<<"Record 1: "<<LinkedList::getList(list_head1)<<endl;

  LinkedListNode* list_head2 = LinkedList::create_linked_list(v2);
  
  cout<<"Record 2: "<<LinkedList::getList(list_head2)<<endl;

  LinkedListNode* merged = merge_sorted(list_head1, list_head2);
  
  cout<<"Consequence: "<<LinkedList::getList(merged)<<endl;

  LinkedListNode* expected_list = LinkedList::create_linked_list(anticipated);
  

  assert(LinkedList::is_equal(merged, expected_list));
}

int most important(int argc, char* argv[]) {

  vector<int> v1 = {1, 3, 5, 6};
  vector<int> v2 = {2, 4, 6, 20, 34};
  vector<int> anticipated = {1, 2, 3, 4, 5, 6, 6, 20, 34};

  check(v1, v2, anticipated);

  v1 = {1, 3, 5, 6};
  v2 = {};
  anticipated = {1, 3, 5, 6};

  check(v1, v2, anticipated);

  v1 = {1, 3, 5, 6};
  v2 = {2, 4, 6, 20};
  anticipated = {1, 2, 3, 4, 5, 6, 6, 20};

  check(v1, v2, anticipated);
  v1 = {4, 4};
  v2 = {4, 4, 4};
  anticipated = {4, 4, 4, 4 ,4};

  check(v1, v2, anticipated);
}

Output

apple interview questions

String Based mostly Questions

  1. Reverse a given sentence. You might be given a sentence and it’s important to reverse the phrases of the sentence. 

When you have two sentences, you’re principally coping with an array of characters. So, the vital and essential half is to take care of the white areas between the phrases. Right here’s how one can code for a similar in C++:

void rev_str(char * str, int len) {

  if (str == nullptr || len < 2) {
    return;
  }

  char * begin = str;
  char * finish = str + len - 1;

  whereas (begin < finish) {
    if (begin != nullptr && finish != nullptr) {
      char temp = * begin;
      * begin = * finish;
      * finish = temp;
    }
    begin++;
    end--;
  }
}

void reverse_words(char * sentence) {

  // Right here sentence is a null-terminated string ending with char ''.

  if (sentence == nullptr) {
    return;
  }

  /*Now first reverse the string to reverse all of the phrases within the sentence. You get all of the phrases within the desired location, however the order of characters within the phrase has been reversed*/

  int len = strlen(sentence);
  rev_str(sentence, len);

    char * begin = sentence;
  char * finish;
  whereas (true) {
    whereas (begin && * begin == ' ') {
      ++begin;
    }

    if (begin == nullptr || * begin == '') {
      break;
    }

    finish = begin + 1;
    whereas (finish && * finish != '' && * finish != ' ') {
      ++finish;
    }

    // Reverse the phrase in-place.

    if (finish != nullptr) {
      rev_str(begin, (finish - begin));
    }

    begin = finish;
  }
}

int most important() {

  string str = "That is my world!";
  char* a = const_cast<char*>(str.c_str());

  cout << a << endl;
  reverse_words(a);
  cout << "Reverse: "<<a << endl;
}

Output

apple interview questions

Dynamic Programming Based mostly Query

  1. For a given constructive quantity ‘n’, decide the utmost sum of any contiguous sub-array of measurement ‘n’ in a given array of constructive integers.

For its resolution, first, discover all of the sub-arrays of measurement ‘n’ and add the numbers in them every time. Additional, examine and return the utmost sum out of the calculated sums. Right here’s its coding implementation in C++

#embody <iostream>
utilizing namespace std;

// Returns most sum in a subarray of measurement n

int max_Sum(int arr[], int m, int n)
{
    // n have to be smaller than m
    if (m < n)
    {
       cout << "Invalid";
       return -1;
    }
 
    // Compute sum of first window of measurement n
    int res = 0;
    for (int i=0; i<n; i++)
       res += arr[i];
 
    
    int curr_sum = res;
    for (int i=n; i<m; i++)
    {
       curr_sum += arr[i] - arr[i-m];
       res = max(res, curr_sum);
    }
 
    return res;
}
  
int most important()
{
    int arr[] = {2, 12, 7, 32, 15, 10, 8};
    int n = 3;
    int m = sizeof(arr)/sizeof(arr[0]);
    cout << max_Sum(arr, m, n);
    return 0;
}

Output

apple interview questions

Backtracking Based mostly Query

  1.  You might be given a goal quantity ‘n’ for which it’s important to discover all of the doable combos that sum as much as make n.

You may recursively undergo all doable sum combos. Show the mixture for which the sum equals ‘n’. Run a ‘for’ loop in every recursive name from the beginning (i=1) to focus on (n). The current_sum variable shops the present sum of every recursive name and is incremented each time.

As a worth is added to the current_sum, it’s concurrently added to the resultant checklist in every recursive name. This resultant checklist is the sum mixture for that specific name. A component is added to the end result earlier than every recursion. Nevertheless, after every recursive name, this aspect should even be faraway from the checklist to reset the checklist. Each time current_sum turns into equal to focus on, the chance for the resultant checklist to comprise the specified mixture arises. This resultant checklist is lastly appended to the output checklist. Right here’s the C++ code for the implementation of the identical:

#embody <iostream>
utilizing namespace std;


void print(vector<vector<int>> output){
  for(int i = 0; i < output.measurement(); i++){
    cout << "[ ";
    for(int j = 0; j < output[i].measurement(); j++){
      cout << output[i][j] << ", "; 
    }
    cout << "]" << endl;
  }
}

void print_all_sum_rec(
    int goal,
    int current_sum,
    int begin, vector<vector<int>>& output,
    vector<int>& end result) {

  if (goal == current_sum) {
    output.push_back(end result);
  }

  for (int i = begin; i < goal; ++i) {
    int temp_sum = current_sum + i;
    if (temp_sum <= goal) {
      end result.push_back(i);
      print_all_sum_rec(goal, temp_sum, i, output, end result);
      end result.pop_back();

    } else {
      return;
    }
  }
}

vector<vector<int>> print_all_sum(int goal) {
  vector<vector<int>> output;
  vector<int> end result;
  print_all_sum_rec(goal, 0, 1, output, end result);
  return output;
}


int most important(int argc, const char* argv[]) {
  int n = 5;
  vector<vector<int>> end result = print_all_sum(n);
  
  print (end result);
}

Output

apple interview questions

Summing Up

So, these have been simply 10 widespread coding apple interview questions that can assist you with the technical interview at Apple. There are various extra comparable questions that may be requested. You have to have gotten a context to the coding issues that may be posted earlier than you. So far as information constructions are involved, you should observe questions primarily based on arrays, linked lists, timber, graphs, hash maps, stacks, queues, and hash units. As for algorithms, you should even be nicely acquainted with binary search, fast type, merge type, depth-first, breadth-first search, and dynamic programming. Study how one can ace coding interviews and land a job at Apple easily.

Better of luck together with your interview preparation! Pleased studying!

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments