Interview Questions

Review this list of 3,949 interview questions and answers verified by hiring managers and candidates.
  • Google logoAsked at Google 
    Software Engineer
  • Apple logoAsked at Apple 

    "The height of a binary tree is the maximum number of edges from the root node to any leaf node. To calculate the height of a binary tree, we can use a recursive approach. The basic idea is to compare the heights of the left and right subtrees of the root node, and return the maximum of them plus one."

    Prashant Y. - "The height of a binary tree is the maximum number of edges from the root node to any leaf node. To calculate the height of a binary tree, we can use a recursive approach. The basic idea is to compare the heights of the left and right subtrees of the root node, and return the maximum of them plus one."See full answer

    Machine Learning Engineer
    Data Structures & Algorithms
    +3 more
  • "class Node { int val; Node left, right; Node(int v) { val = v; left = right = null; } } class BinaryTree { Node root1, root2; boolean identicalTrees(Node a, Node b) { if (a == null && b == null) return true; if (a != null && b != null) return (a.val == b.val && identicalTrees(a.left, b.left) && identicalTrees(a.right, b.right)); "

    Tushar A. - "class Node { int val; Node left, right; Node(int v) { val = v; left = right = null; } } class BinaryTree { Node root1, root2; boolean identicalTrees(Node a, Node b) { if (a == null && b == null) return true; if (a != null && b != null) return (a.val == b.val && identicalTrees(a.left, b.left) && identicalTrees(a.right, b.right)); "See full answer

    Coding
    Data Structures & Algorithms
  • +1

    "You may backtracking it but I don't see what relation this matrix represents?"

    Denis F. - "You may backtracking it but I don't see what relation this matrix represents?"See full answer

  • 🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.

  • Amazon logoAsked at Amazon 

    "USING RECURSION"

    Flora K. - "USING RECURSION"See full answer

    Data Structures & Algorithms
    Coding
  • "htrhtrd"

    Rabiul H. - "htrhtrd"See full answer

    Technical Program Manager
  • Adobe logoAsked at Adobe 
    Video answer for 'Print all possible solutions to the N-Queens problem.'
    Data Engineer
    Coding
    +2 more
  • Mastercard logoAsked at Mastercard 

    "min-num = arr[0] max-num = arr[0] for (i=1; i max-num) { max-num = arr[i]; } } System.out.println("Minimum = " + min-num); System.out.println("Maximum = " + max-num);"

    Kamlesh S. - "min-num = arr[0] max-num = arr[0] for (i=1; i max-num) { max-num = arr[i]; } } System.out.println("Minimum = " + min-num); System.out.println("Maximum = " + max-num);"See full answer

    Software Engineer
    Technical
  • Apple logoAsked at Apple 

    Coin Change

    IDE
    Medium
    +6

    "The example given is wrong. The 2nd test case should have answer 3, as we can get to 6 by using 3 coins of denomination 2."

    Anmol R. - "The example given is wrong. The 2nd test case should have answer 3, as we can get to 6 by using 3 coins of denomination 2."See full answer

    Backend Engineer
    Coding
    +3 more
  • +1

    "// array is sorted in non-increasing order // low = 0, high = arr.length - 1 int countOnes(int[] arr, int low, int high) { if (high >= low) { int mid = low + (high - low) / 2; if ((mid == high || arr[mid + 1] == 0) && (arr[mid] == 1)) { return mid + 1; } if (arr[mid] == 1) { return countOnes(arr, (mid + 1), high); } return countOnes(arr, low, (mid - 1)); } return 0; }"

    Shubhendu K. - "// array is sorted in non-increasing order // low = 0, high = arr.length - 1 int countOnes(int[] arr, int low, int high) { if (high >= low) { int mid = low + (high - low) / 2; if ((mid == high || arr[mid + 1] == 0) && (arr[mid] == 1)) { return mid + 1; } if (arr[mid] == 1) { return countOnes(arr, (mid + 1), high); } return countOnes(arr, low, (mid - 1)); } return 0; }"See full answer

    Technical
  • "package mycoding.tryexponent.com; import java.util.Scanner; public class FirstAndLastOccurenceOfaNumber { public static void main(String[] arg) { System.out.println("Enter 'a' to run the programme:"); System.out.println("Enter 't' to terminate the programme:"); Scanner in=new Scanner(System.in); String inputtedString=in.nextLine(); while(!"t".equalsIgnoreCase(inputtedString)) { System.out.println("enter a number to find its 1st nd last occurence"); int number=in.nextInt(); int[] array=new i"

    Ankur T. - "package mycoding.tryexponent.com; import java.util.Scanner; public class FirstAndLastOccurenceOfaNumber { public static void main(String[] arg) { System.out.println("Enter 'a' to run the programme:"); System.out.println("Enter 't' to terminate the programme:"); Scanner in=new Scanner(System.in); String inputtedString=in.nextLine(); while(!"t".equalsIgnoreCase(inputtedString)) { System.out.println("enter a number to find its 1st nd last occurence"); int number=in.nextInt(); int[] array=new i"See full answer

    Technical
  • Microsoft logoAsked at Microsoft 
    Video answer for 'Find the number of rotations in a circularly sorted array.'
    +8

    "function countRotations(arr, low, high) { if (high low && arr[mid] arr[mid]) { return countRotations(arr, low, mid - 1); } return countRotations(arr, mid + 1, high); } "

    Ugo C. - "function countRotations(arr, low, high) { if (high low && arr[mid] arr[mid]) { return countRotations(arr, low, mid - 1); } return countRotations(arr, mid + 1, high); } "See full answer

    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Google logoAsked at Google 

    "Binary search is commonly used for searching elements in a sorted array. Most searching algorithms take O(n) time, but binary search operates in O(log(n)) time complexity. function binarySearch(arr, target) { let first = 0; let last = arr.length - 1; // Adjusted to correctly represent the last index while (first target) { last = mid - 1; } "

    Satyam S. - "Binary search is commonly used for searching elements in a sorted array. Most searching algorithms take O(n) time, but binary search operates in O(log(n)) time complexity. function binarySearch(arr, target) { let first = 0; let last = arr.length - 1; // Adjusted to correctly represent the last index while (first target) { last = mid - 1; } "See full answer

    Frontend Engineer
    Technical
  • "Steps: Validate K to be less than the number of elements in an array. Sort the array in ascending order. Get the K'th smallest element by array[k-1]."

    Ashesh S. - "Steps: Validate K to be less than the number of elements in an array. Sort the array in ascending order. Get the K'th smallest element by array[k-1]."See full answer

  • "As the array is sorted, would it best to use binary search to find the one the triplet and just navigate from it."

    Anonymous Narwhal - "As the array is sorted, would it best to use binary search to find the one the triplet and just navigate from it."See full answer

    Technical
  • "bool isConsecutive(int arr[], int n) { // base case if (n max) { max = arr[i]; } } // for an array to contain consecutive integers, the difference between // the maximum and minimum element in it should be exactly \n-1\ if (max - min != n - 1) { return false; } // create an empty set (we can also use a visit"

    Hinata T. - "bool isConsecutive(int arr[], int n) { // base case if (n max) { max = arr[i]; } } // for an array to contain consecutive integers, the difference between // the maximum and minimum element in it should be exactly \n-1\ if (max - min != n - 1) { return false; } // create an empty set (we can also use a visit"See full answer

Showing 2941-2960 of 3949