Coding Interview Questions

Review this list of 344 coding interview questions and answers verified by hiring managers and candidates.
  • Amazon logoAsked at Amazon 
    +2

    " This is mostly correct and fairly fast. My code has a bug somewhere where it fails on cases like the last case, where there are negative number on both ends of the array and the sums . from collections import deque debug = True # False def prdbg(*x): global debug debug = True # False if debug: print(x) else: return def max_sum(arr, start, end): if type(arr) == type(''' "

    Nathan B. - " This is mostly correct and fairly fast. My code has a bug somewhere where it fails on cases like the last case, where there are negative number on both ends of the array and the sums . from collections import deque debug = True # False def prdbg(*x): global debug debug = True # False if debug: print(x) else: return def max_sum(arr, start, end): if type(arr) == type(''' "See full answer

    Coding
    Data Structures & Algorithms
  • Apple logoAsked at Apple 
    Software Engineer
    Coding
    +1 more
  • Apple logoAsked at Apple 
    Data Engineer
    Coding
    +1 more
  • "Using a join: This is the most common way to do a lookup."

    Praful B. - "Using a join: This is the most common way to do a lookup."See full answer

    Coding
  • Software Engineer
    Coding
    +1 more
  • 🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.

  • Apple logoAsked at Apple 
    Software Engineer
    Coding
    +1 more
  • "I wrote a function to determine if a given number is a power of 2 using logarithms."

    Susheel C. - "I wrote a function to determine if a given number is a power of 2 using logarithms."See full answer

    Software Engineer
    Coding
    +1 more
  • Apple logoAsked at Apple 
    Software Engineer
    Coding
    +1 more
  • 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
  • LinkedIn logoAsked at LinkedIn 

    "Basic Approach As BST inorder traversal will result in a sequence of increasing order. Store that order in a vector and get the k-1 index to get the Kth smallest element, similarly access the N-K+1 th element will be the Kth largest element Time Complexity: O(n) Space Complexity O(n) Space Optimized Approach For Kth smallest , start inorder traversal, and keep a counter, decrement the counter when you access the node element. When the counter turns 0 that elementwill be the Kth smal"

    Saurabh S. - "Basic Approach As BST inorder traversal will result in a sequence of increasing order. Store that order in a vector and get the k-1 index to get the Kth smallest element, similarly access the N-K+1 th element will be the Kth largest element Time Complexity: O(n) Space Complexity O(n) Space Optimized Approach For Kth smallest , start inorder traversal, and keep a counter, decrement the counter when you access the node element. When the counter turns 0 that elementwill be the Kth smal"See full answer

    Coding
    Data Structures & Algorithms
    +1 more
  • Meta (Facebook) logoAsked at Meta (Facebook) 
    Machine Learning Engineer
    Coding
    +1 more
  • "int a_array[10] = {3,6,4,7,2,1,9}; int index = 0; int index2 = 0; for ( index = 0; index < sizeof(a_array); index++ ) { int tmpindex = index + 1; if ( tmpindex <= sizeof(a_array) ) { for ( index2 = tmpindex; index2 < sizeof(a_array); index2++ ) { if ( aarray[index] <= aarray[index2] ) { print( "%d is the NGE of %d" array[index2], array[index]); break; "

    Mark S. - "int a_array[10] = {3,6,4,7,2,1,9}; int index = 0; int index2 = 0; for ( index = 0; index < sizeof(a_array); index++ ) { int tmpindex = index + 1; if ( tmpindex <= sizeof(a_array) ) { for ( index2 = tmpindex; index2 < sizeof(a_array); index2++ ) { if ( aarray[index] <= aarray[index2] ) { print( "%d is the NGE of %d" array[index2], array[index]); break; "See full answer

    Software Engineer
    Coding
    +1 more
  • JP Morgan Chase logoAsked at JP Morgan Chase 
    Software Engineer
    Coding
    +1 more
  • Adobe logoAsked at Adobe 
    +6

    "function isPalindrome(s, start, end) { while (s[start] === s[end] && end >= start) { start++; end--; } return end <= start; } function longestPalindromicSubstring(s) { let longestPalindrome = ''; for (let i=0; i < s.length; i++) { let j = s.length-1; while (s[i] !== s[j] && i <= j) { j--; } if (s[i] === s[j]) { if (isPalindrome(s, i, j)) { const validPalindrome = s.substring(i, j+1"

    Tiago R. - "function isPalindrome(s, start, end) { while (s[start] === s[end] && end >= start) { start++; end--; } return end <= start; } function longestPalindromicSubstring(s) { let longestPalindrome = ''; for (let i=0; i < s.length; i++) { let j = s.length-1; while (s[i] !== s[j] && i <= j) { j--; } if (s[i] === s[j]) { if (isPalindrome(s, i, j)) { const validPalindrome = s.substring(i, j+1"See full answer

    Data Engineer
    Coding
    +3 more
  • Meta (Facebook) logoAsked at Meta (Facebook) 
    Machine Learning Engineer
    Coding
    +1 more
  • Google Cloud (GCP) logoAsked at Google Cloud (GCP) 

    "(Like a Rummy Game) There are 3 colors of tiles. Each tile has a number 1-9 on it. So the 27-tile set makes a deck. There are 4 decks. (Total = 108 tiles) Tile Colors = {Red, Black, Green} The tiles could be grouped together in patterns Types of patterns : The three tiles are identical (R2, R2, R2) The three tiles are of same color and sequential (R2, R3, R4). Sequence cannot be overlapping (R8, R9, R1 is not a pattern) Help : Tile Notations - R2 denotes Red tile having num 2 A player"

    Gopal D. - "(Like a Rummy Game) There are 3 colors of tiles. Each tile has a number 1-9 on it. So the 27-tile set makes a deck. There are 4 decks. (Total = 108 tiles) Tile Colors = {Red, Black, Green} The tiles could be grouped together in patterns Types of patterns : The three tiles are identical (R2, R2, R2) The three tiles are of same color and sequential (R2, R3, R4). Sequence cannot be overlapping (R8, R9, R1 is not a pattern) Help : Tile Notations - R2 denotes Red tile having num 2 A player"See full answer

    Software Engineer
    Coding
  • " First, sort the array in ascending order. This ensures that we can easily check the triangle inequality condition. Use a loop to iterate through the array. For each triplet of consecutive elements, check if they satisfy the triangle inequality condition a+b>ca+b>c. As soon as you find a valid tuple, return it. If no valid tuple is found, return null. This approach is efficient with a time complexity of O(nlog⁡n)O(nlogn) due to the sorting step, followed by a linear scan of the array"

    Shivam P. - " First, sort the array in ascending order. This ensures that we can easily check the triangle inequality condition. Use a loop to iterate through the array. For each triplet of consecutive elements, check if they satisfy the triangle inequality condition a+b>ca+b>c. As soon as you find a valid tuple, return it. If no valid tuple is found, return null. This approach is efficient with a time complexity of O(nlog⁡n)O(nlogn) due to the sorting step, followed by a linear scan of the array"See full answer

    Machine Learning Engineer
    Coding
    +1 more
  • Apple logoAsked at Apple 
    +2

    "Make current as root. 2 while current is not null, if p and q are less than current, go left. If p and q are greater than current, go right. else return current. return null"

    Vaibhav D. - "Make current as root. 2 while current is not null, if p and q are less than current, go left. If p and q are greater than current, go right. else return current. return null"See full answer

    Software Engineer
    Coding
    +4 more
  • Google logoAsked at Google 
    Machine Learning Engineer
    Coding
    +1 more
  • "I first asked few clarifying questions like the return array may need not contain the list of building in the same order, to which the interviewer agreed. Then I came up with an approach where we iterate the array from right to left and keep a max variable which will keep the value of the current max. When we find an item which is greater than max we update the max and add this element into our solution. The interviewer agreed for the approach. I discussed few corner scenarios with the interview"

    Rishabh N. - "I first asked few clarifying questions like the return array may need not contain the list of building in the same order, to which the interviewer agreed. Then I came up with an approach where we iterate the array from right to left and keep a max variable which will keep the value of the current max. When we find an item which is greater than max we update the max and add this element into our solution. The interviewer agreed for the approach. I discussed few corner scenarios with the interview"See full answer

    Software Engineer
    Coding
    +1 more
Showing 281-300 of 344