Recent Coding Interview Questions

Review this list of 363 coding interview questions and answers verified by hiring managers and candidates.
  • "Function signature for reference: def calculate(servers: List[int], k: int) -> int: ... To resolve this, you can use binary search considering left=0 and right=max(servers) * k so Example: servers=[1,4,5] First server handle 1 request in let's say 1 second, second 4 seconds and last 5 seconds. k=10 So I want to know the minimal time to process 10 requests Get the mid for timeline mid = (left+right)//2 -> mid is 25 Check how many we could process 25//1 = 25 25//4=6 25//5=5 so 25 + 6 +"

    Babaa - "Function signature for reference: def calculate(servers: List[int], k: int) -> int: ... To resolve this, you can use binary search considering left=0 and right=max(servers) * k so Example: servers=[1,4,5] First server handle 1 request in let's say 1 second, second 4 seconds and last 5 seconds. k=10 So I want to know the minimal time to process 10 requests Get the mid for timeline mid = (left+right)//2 -> mid is 25 Check how many we could process 25//1 = 25 25//4=6 25//5=5 so 25 + 6 +"See full answer

    Software Engineer
    Coding
  • Amazon logoAsked at Amazon 

    "It was like say we have a library A which has a library B as a dependency and so on, how would we determine in the dependency chain that whether there is a circular depedency?"

    Chris R. - "It was like say we have a library A which has a library B as a dependency and so on, how would we determine in the dependency chain that whether there is a circular depedency?"See full answer

    Software Engineer
    Coding
    +1 more
  • Microsoft logoAsked at Microsoft 

    "int reverse(int x) { int rev = 0; bool isNegative = false; if(x 0){ int r = x % 10; rev = rev * 10 + r; x = x / 10; } if(isNegative){ return -rev; } return rev; } `"

    Nilay B. - "int reverse(int x) { int rev = 0; bool isNegative = false; if(x 0){ int r = x % 10; rev = rev * 10 + r; x = x / 10; } if(isNegative){ return -rev; } return rev; } `"See full answer

    Software Engineer
    Coding
    +1 more
  • "Sorted the array and stored the minimum difference in a variable and then traversed the array for the pairs having minimum difference"

    Aashka C. - "Sorted the array and stored the minimum difference in a variable and then traversed the array for the pairs having minimum difference"See full answer

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

  • Machine Learning Engineer
    Coding
    +1 more
  • Software Engineer
    Coding
    +1 more
  • Software Engineer
    Coding
    +1 more
  • "find total sum. assign that to rightsum traverse from left to right: keep updating left sum and right sum, when they match return the index. else if you reach end return -1 or not found"

    Rahul J. - "find total sum. assign that to rightsum traverse from left to right: keep updating left sum and right sum, when they match return the index. else if you reach end return -1 or not found"See full answer

    Software Engineer
    Coding
    +1 more
  • "I would assume that this is similar to an intervals question. Meeting Rooms II (https://www.lintcode.com/problem/919/?fromId=203&_from=collection) on Leetcode seems like the closest comparison, it's a premium question so I linked Lintcode. I'm assuming that we also need to just return the minimum number of cars used. You need to sort for the most optimal solution, so you're constrained by an O(nlogn) time complexity. So any sorting solution could work (using a heap, sorting the array input arra"

    Sohum S. - "I would assume that this is similar to an intervals question. Meeting Rooms II (https://www.lintcode.com/problem/919/?fromId=203&_from=collection) on Leetcode seems like the closest comparison, it's a premium question so I linked Lintcode. I'm assuming that we also need to just return the minimum number of cars used. You need to sort for the most optimal solution, so you're constrained by an O(nlogn) time complexity. So any sorting solution could work (using a heap, sorting the array input arra"See full answer

    Software Engineer
    Coding
    +1 more
  • "/* You are with your friends in a castle, where there are multiple rooms named after flowers. Some of the rooms contain treasures - we call them the treasure rooms. Each room contains a single instruction that tells you which room to go to next. * instructions1 and treasurerooms_1 * lily* --------- daisy sunflower | | | v v v jasmin --> tulip* violet* ----> rose* --> ^ | ^ ^ | "

    Azeezat R. - "/* You are with your friends in a castle, where there are multiple rooms named after flowers. Some of the rooms contain treasures - we call them the treasure rooms. Each room contains a single instruction that tells you which room to go to next. * instructions1 and treasurerooms_1 * lily* --------- daisy sunflower | | | v v v jasmin --> tulip* violet* ----> rose* --> ^ | ^ ^ | "See full answer

    Software Engineer
    Coding
    +1 more
  • "I solved it using recursion and then memoization. Used Dynamic programming approach"

    Ravi teja N. - "I solved it using recursion and then memoization. Used Dynamic programming approach"See full answer

    Software Engineer
    Coding
    +1 more
  • Google logoAsked at Google 

    "Question: An array of n integers is given, and a positive integer k, where k << n. k indicates that the absolute difference between each element's current index (icurrent) and the index in the sorted array (isorted) is less than k (|icurr - isorted| < k). Sort the given array. The most common solution is with a Heap: def solution(arr, k): min_heap = [] result = [] for i in range(len(arr)) heapq.heappush(min_heap, arr[i]) "

    Guilherme M. - "Question: An array of n integers is given, and a positive integer k, where k << n. k indicates that the absolute difference between each element's current index (icurrent) and the index in the sorted array (isorted) is less than k (|icurr - isorted| < k). Sort the given array. The most common solution is with a Heap: def solution(arr, k): min_heap = [] result = [] for i in range(len(arr)) heapq.heappush(min_heap, arr[i]) "See full answer

    Software Engineer
    Coding
    +1 more
  • TikTok logoAsked at TikTok 

    "class Solution: def lengthOfLIS(self, nums: List[int]) -> int: temp = [nums[0]] for num in nums: if temp[-1]< num: temp.append(num) else: index = bisect_left(temp,num) temp[index] = num return len(temp) "

    Mahima M. - "class Solution: def lengthOfLIS(self, nums: List[int]) -> int: temp = [nums[0]] for num in nums: if temp[-1]< num: temp.append(num) else: index = bisect_left(temp,num) temp[index] = num return len(temp) "See full answer

    Machine Learning Engineer
    Coding
    +1 more
  • "2 Approaches: 1) The more intuitive approach is doing a multi-source BFS from all cats and storing the distance of closest cats. Then do a dfs/bfs from rat to bread. Time Complexity: O(mn + 4^L) where L is path length, worst case L could be mn Space Complexity: O(m*n) 2) The first approach should be fine for interviews. But if they ask to optimize it further, you can use Binary Search. Problems like "Finding max of min distance" or "Finding min of max" could be usually solved by BS. "

    Karan K. - "2 Approaches: 1) The more intuitive approach is doing a multi-source BFS from all cats and storing the distance of closest cats. Then do a dfs/bfs from rat to bread. Time Complexity: O(mn + 4^L) where L is path length, worst case L could be mn Space Complexity: O(m*n) 2) The first approach should be fine for interviews. But if they ask to optimize it further, you can use Binary Search. Problems like "Finding max of min distance" or "Finding min of max" could be usually solved by BS. "See full answer

    Software Engineer
    Coding
    +1 more
  • Meta (Facebook) logoAsked at Meta (Facebook) 

    "Coded the solution using this approach that is frequency table and counting. it is Leetcode 791"

    Anonymous Porcupine - "Coded the solution using this approach that is frequency table and counting. it is Leetcode 791"See full answer

    Mobile Engineer
    Coding
  • Meta (Facebook) logoAsked at Meta (Facebook) 

    "https://www.geeksforgeeks.org/find-local-minima-array/ I coded O(N) but after that gave a binary approach aswell. After that he also gave a varient of this problem in which, local minima means that the number is strictly less than its adjacent (we cannot do binary search there sample test case [1,1,1,1,1,1,0,1] or [1,0,1,1,1,1,1,1] using mid we cannot determine if the minima is on left or right). we have to do a linear search or find recursively."

    Anonymous Porcupine - "https://www.geeksforgeeks.org/find-local-minima-array/ I coded O(N) but after that gave a binary approach aswell. After that he also gave a varient of this problem in which, local minima means that the number is strictly less than its adjacent (we cannot do binary search there sample test case [1,1,1,1,1,1,0,1] or [1,0,1,1,1,1,1,1] using mid we cannot determine if the minima is on left or right). we have to do a linear search or find recursively."See full answer

    Mobile Engineer
    Coding
  • LinkedIn logoAsked at LinkedIn 

    "Used prefix & postfix sums, resetting the product when 0 was found"

    Rg - "Used prefix & postfix sums, resetting the product when 0 was found"See full answer

    Software Engineer
    Coding
  • Microsoft logoAsked at Microsoft 
    +1

    "#simple solution 1.firstly find the node in the bst (O(logn) time complexity it take) 2.now removing the node consists of 3 cases: 1.if the node is leaf (no children): (keep track of parent and do) parent.left or parent.right=NULL simply remove the node () 2.if(has one child) replace the node with its child 3.if has both childs we replace the node with either inorder predesor(max of left tree)or inorder succesor and remove the node wh"

    Sambangi C. - "#simple solution 1.firstly find the node in the bst (O(logn) time complexity it take) 2.now removing the node consists of 3 cases: 1.if the node is leaf (no children): (keep track of parent and do) parent.left or parent.right=NULL simply remove the node () 2.if(has one child) replace the node with its child 3.if has both childs we replace the node with either inorder predesor(max of left tree)or inorder succesor and remove the node wh"See full answer

    Software Engineer
    Coding
  • Coinbase logoAsked at Coinbase 
    Frontend Engineer
    Coding
Showing 1-20 of 363