Recent Coding Interview Questions

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

    "check the count of both sentences if the same then start loop on words count and check the presence of words are the same."

    Suleman A. - "check the count of both sentences if the same then start loop on words count and check the presence of words are the same."See full answer

    Software Engineer
    Coding
    +2 more
  • +5

    "function knapsack(weights, values, cap) { const indicesByValue = Object.keys(weights).map(weight => parseInt(weight)); indicesByValue.sort((a, b) => values[b]-values[a]); const steps = new Map(); function knapsackStep(cap, sack) { if (steps.has(sack)) { return steps.get(sack); } let maxOutput = 0; for (let index of indicesByValue) { if (!sack.has(index) && weights[index] <= cap) { maxOutput ="

    Tiago R. - "function knapsack(weights, values, cap) { const indicesByValue = Object.keys(weights).map(weight => parseInt(weight)); indicesByValue.sort((a, b) => values[b]-values[a]); const steps = new Map(); function knapsackStep(cap, sack) { if (steps.has(sack)) { return steps.get(sack); } let maxOutput = 0; for (let index of indicesByValue) { if (!sack.has(index) && weights[index] <= cap) { maxOutput ="See full answer

    Software Engineer
    Coding
    +2 more
  • Adobe logoAsked at Adobe 
    Video answer for 'Product of Array Except Self'
    +39

    "from typing import List def productExceptSelf(nums: List[int]) -> List[int]: if len(nums) <= 1: raise Exception("nums must contain at least 2 items.") Initialize totalProduct to the first number in nums. Later, we will populate this as the product of ALL numbers in nums. totalProduct = nums[0] if nums[0] != 0 else 1 If there is more than 1 zero in nums, all products will end up zero. But if there's only 1 zero, there will be 1 nonzer"

    Gemma S. - "from typing import List def productExceptSelf(nums: List[int]) -> List[int]: if len(nums) <= 1: raise Exception("nums must contain at least 2 items.") Initialize totalProduct to the first number in nums. Later, we will populate this as the product of ALL numbers in nums. totalProduct = nums[0] if nums[0] != 0 else 1 If there is more than 1 zero in nums, all products will end up zero. But if there's only 1 zero, there will be 1 nonzer"See full answer

    Software Engineer
    Coding
    +3 more
  • Flatiron Health logoAsked at Flatiron Health 
    Software Engineer
    Coding
    +2 more
  • "public Double calculateRatio(String source, String destination) { Double ratio=1.0; while(graph.containsKey(source) && !visited.contains(source)) { visited.add(source); Map valueMap=graph.get(source); if(valueMap.containsKey(destination)) { return ratio*=valueMap.get(destination); } Map.Entry firstEntry=valueMap.entrySet().iterator().next(); source=firstEntry.getKey(); ratio*=firstEntry.getValue(); System.out.println("Entered"); } return null; }"

    Divya R. - "public Double calculateRatio(String source, String destination) { Double ratio=1.0; while(graph.containsKey(source) && !visited.contains(source)) { visited.add(source); Map valueMap=graph.get(source); if(valueMap.containsKey(destination)) { return ratio*=valueMap.get(destination); } Map.Entry firstEntry=valueMap.entrySet().iterator().next(); source=firstEntry.getKey(); ratio*=firstEntry.getValue(); System.out.println("Entered"); } return null; }"See full answer

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

  • Software Engineer
    Coding
    +1 more
  • Adobe logoAsked at Adobe 

    Permutations

    IDE
    Medium

    "function permute(nums) { if (nums.length <= 1) { return [nums]; } const prevPermutations = permute(nums.slice(0, nums.length-1)); const currentNum = nums[nums.length-1]; const permutations = new Set(); for (let prev of prevPermutations) { for (let i=0; i < prev.length; i++) { permutations.add([...prev.slice(0, i), currentNum, ...prev.slice(i)]); } permutations.add([...prev, currentNum]); } return [...permutations]"

    Tiago R. - "function permute(nums) { if (nums.length <= 1) { return [nums]; } const prevPermutations = permute(nums.slice(0, nums.length-1)); const currentNum = nums[nums.length-1]; const permutations = new Set(); for (let prev of prevPermutations) { for (let i=0; i < prev.length; i++) { permutations.add([...prev.slice(0, i), currentNum, ...prev.slice(i)]); } permutations.add([...prev, currentNum]); } return [...permutations]"See full answer

    Software Engineer
    Coding
    +3 more
  • Dropbox logoAsked at Dropbox 
    Video answer for 'Find duplicate files in a file system.'

    " read_dir(path: str) -> list[str] returns the full path of all files and sub- directories of a given directory. is_file(path: str) -> bool: returns true if the path points to a regular file. is_dir(path: str) -> bool: returns true if the path points to a directory. read_file(path: str) -> str: reads and returns the content of the file. The algorithm: notice that storing all the file contents' is too space intensive, so we can't read all the files' contents to store and compare with each"

    Idan R. - " read_dir(path: str) -> list[str] returns the full path of all files and sub- directories of a given directory. is_file(path: str) -> bool: returns true if the path points to a regular file. is_dir(path: str) -> bool: returns true if the path points to a directory. read_file(path: str) -> str: reads and returns the content of the file. The algorithm: notice that storing all the file contents' is too space intensive, so we can't read all the files' contents to store and compare with each"See full answer

    Software Engineer
    Coding
    +2 more
  • Amazon logoAsked at Amazon 

    "Use Dijkstra's Algorithm with priority queue"

    Karthik R. - "Use Dijkstra's Algorithm with priority queue"See full answer

    Software Engineer
    Coding
    +2 more
  • Adobe logoAsked at Adobe 

    "Leetcode 347: Heap + Hashtable Follow up question: create heap with the length of K instead of N (more time complexity but less space )"

    Chen J. - "Leetcode 347: Heap + Hashtable Follow up question: create heap with the length of K instead of N (more time complexity but less space )"See full answer

    Data Engineer
    Coding
    +3 more
  • "def findAlibaba(countOfRooms, strategy): #countofrooms: num rooms #listRooms rooms to look for alibabba possiblePlaces = [] #initialize rooms for i in range(countOfRooms): possiblePlaces.append(True) for i in range(len(strategy)): roomToCheck = strategy[i] #Room is marked as unavailable possiblePlaces[roomToCheck] = False #Next day calculatins nextDayPlaces = [] for j in range(countOfRooms): nextDayPla"

    JOBHUNTER - "def findAlibaba(countOfRooms, strategy): #countofrooms: num rooms #listRooms rooms to look for alibabba possiblePlaces = [] #initialize rooms for i in range(countOfRooms): possiblePlaces.append(True) for i in range(len(strategy)): roomToCheck = strategy[i] #Room is marked as unavailable possiblePlaces[roomToCheck] = False #Next day calculatins nextDayPlaces = [] for j in range(countOfRooms): nextDayPla"See full answer

    Engineering Manager
    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
  • "I try to solve this initially using quick select where will take a pivot element and position the remaining elements and check if the current index is answer or not and continue the same but it requires o(n*n), but interviewee is expecting the best from me, so at the end i tried solving using heaps where will check the difference between k and n-k to use min or max heap after that we will heap the array, and will keep popping the element k-1 and return the peek one which leads to answer."

    Mourya C. - "I try to solve this initially using quick select where will take a pivot element and position the remaining elements and check if the current index is answer or not and continue the same but it requires o(n*n), but interviewee is expecting the best from me, so at the end i tried solving using heaps where will check the difference between k and n-k to use min or max heap after that we will heap the array, and will keep popping the element k-1 and return the peek one which leads to answer."See full answer

    Software Engineer
    Coding
    +2 more
  • Bolt logoAsked at Bolt 
    Software Engineer
    Coding
    +1 more
  • +4

    "Definitely nice to think of this without memorization, but there is a well known algorithm for this problem, which is the Levenshtein Distance. Lev(a,b) = len(a) if len(b) == 0 = len(b) if len(a) == 0 = lev(a[1:], b[1:] if a[0] == b[0] = 1 + min (lev(a, b[1:]), lev(a[1:], b), lev(a[1:], b[1:])) https://en.wikipedia.org/wiki/Levenshtein_distance I'm sure some optimizations could be made with heuristic."

    Nicholas S. - "Definitely nice to think of this without memorization, but there is a well known algorithm for this problem, which is the Levenshtein Distance. Lev(a,b) = len(a) if len(b) == 0 = len(b) if len(a) == 0 = lev(a[1:], b[1:] if a[0] == b[0] = 1 + min (lev(a, b[1:]), lev(a[1:], b), lev(a[1:], b[1:])) https://en.wikipedia.org/wiki/Levenshtein_distance I'm sure some optimizations could be made with heuristic."See full answer

    Software Engineer
    Coding
    +1 more
  • "let str = 'this is a test of programs'; let obj={}; for (let s of str ) obj[s]?(obj[s]=obj[s]+1):(obj[s]=1) console.log(JSON.stringify(obj))"

    Anonymous Emu - "let str = 'this is a test of programs'; let obj={}; for (let s of str ) obj[s]?(obj[s]=obj[s]+1):(obj[s]=1) console.log(JSON.stringify(obj))"See full answer

    Software Engineer
    Coding
    +2 more
  • +9

    "from typing import List def maxprofitgreedy(stock_prices: List[int]) -> int: l=0 # buying r=1 # selling max_profit=0 while rstock_prices[l]: profit=stockprices[r]-stockprices[l] maxprofit=max(maxprofit,profit) else: l=r r+=1 return max_profit debug your code below print(maxprofitgreedy([7, 1, 5, 3, 6, 4])) `"

    Prajwal M. - "from typing import List def maxprofitgreedy(stock_prices: List[int]) -> int: l=0 # buying r=1 # selling max_profit=0 while rstock_prices[l]: profit=stockprices[r]-stockprices[l] maxprofit=max(maxprofit,profit) else: l=r r+=1 return max_profit debug your code below print(maxprofitgreedy([7, 1, 5, 3, 6, 4])) `"See full answer

    Software Engineer
    Coding
    +4 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
  • Airbnb logoAsked at Airbnb 
    Video answer for 'Find the minimum window substring.'

    "sliding window"

    Ashley M. - "sliding window"See full answer

    Software Engineer
    Coding
    +1 more
  • Databricks logoAsked at Databricks 

    "You will need to start from Browser and go all the way up to Analytic systems and methods. Everything needs to be covered"

    Divya K. - "You will need to start from Browser and go all the way up to Analytic systems and methods. Everything needs to be covered"See full answer

    Technical Program Manager
    Coding
    +2 more
Showing 281-300 of 344