Coding Interview Questions

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

    "dp"

    Brajesh J. - "dp"See full answer

    Coding
    Data Structures & Algorithms
  • Visa logoAsked at Visa 
    Software Engineer
    Coding
    +1 more
  • Adobe logoAsked at Adobe 
    +7

    "from typing import List def traprainwater(height: List[int]) -> int: if not height: return 0 l, r = 0, len(height) - 1 leftMax, rightMax = height[l], height[r] res = 0 while l < r: if leftMax < rightMax: l += 1 leftMax = max(leftMax, height[l]) res += leftMax - height[l] else: r -= 1 rightMax = max(rightMax, height[r]) "

    Anonymous Roadrunner - "from typing import List def traprainwater(height: List[int]) -> int: if not height: return 0 l, r = 0, len(height) - 1 leftMax, rightMax = height[l], height[r] res = 0 while l < r: if leftMax < rightMax: l += 1 leftMax = max(leftMax, height[l]) res += leftMax - height[l] else: r -= 1 rightMax = max(rightMax, height[r]) "See full answer

    Software Engineer
    Coding
    +4 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
  • Amazon logoAsked at Amazon 

    "na"

    Nishigandha B. - "na"See full answer

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

  • Amazon logoAsked at Amazon 

    "Use a BFS"

    Kwaku K. - "Use a BFS"See full answer

    Software Engineer
    Coding
    +2 more
  • "As we can pass info to only one child at a time, I told that from any given node, we have to pass the info to that child(of this node) which has the largest subtree rooted at it. To calculate the subtree sizes, I used DFS. And then to calculate the minimum time to pass info to all the nodes, I used BFS picking the largest subtree child first at every node. I couldn't write the complete code in the given time and also made a mistake in telling the overall time complexity of my approach. I think t"

    Lakshman B. - "As we can pass info to only one child at a time, I told that from any given node, we have to pass the info to that child(of this node) which has the largest subtree rooted at it. To calculate the subtree sizes, I used DFS. And then to calculate the minimum time to pass info to all the nodes, I used BFS picking the largest subtree child first at every node. I couldn't write the complete code in the given time and also made a mistake in telling the overall time complexity of my approach. I think t"See full answer

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

    "func isMatch(text: String, pattern: String) -> Bool { // Convert strings to arrays for easier indexing let s = Array(text.characters) let p = Array(pattern.characters) guard !s.isEmpty && !p.isEmpty else { return true } // Create DP table: dpi represents if s[0...i-1] matches p[0...j-1] var dp = Array(repeating: Array(repeating: false, count: p.count + 1), count: s.count + 1) // Empty pattern matches empty string dp[0]["

    Vince S. - "func isMatch(text: String, pattern: String) -> Bool { // Convert strings to arrays for easier indexing let s = Array(text.characters) let p = Array(pattern.characters) guard !s.isEmpty && !p.isEmpty else { return true } // Create DP table: dpi represents if s[0...i-1] matches p[0...j-1] var dp = Array(repeating: Array(repeating: false, count: p.count + 1), count: s.count + 1) // Empty pattern matches empty string dp[0]["See full answer

    Machine Learning Engineer
    Coding
    +3 more
  • Flatiron Health logoAsked at Flatiron Health 
    Software Engineer
    Coding
    +2 more
  • Goldman Sachs logoAsked at Goldman Sachs 

    "standard answer for this."

    Shar N. - "standard answer for this."See full answer

    Software Engineer
    Coding
    +1 more
  • "boolean isMatch(String s, String p) { int i=0; int j=0; int sID=-1; int prevM=-1; while(i<s.length()){ if(j<p.length() && (s.charAt(i)==p.charAt(j) || p.charAt(j)=='?')){ i++; j++; }else if(j<p.length() && p.charAt(j)=='*'){ sID=j; prevM=i; j++; }else if(sID!=-1){ j=sID+1; prevM++; i=prevM; }else{ return false; } } while(j<p.length() && p.charAt(j)=='*') j++; if(i!=s.length() || j!=p.leng"

    Ravi C. - "boolean isMatch(String s, String p) { int i=0; int j=0; int sID=-1; int prevM=-1; while(i<s.length()){ if(j<p.length() && (s.charAt(i)==p.charAt(j) || p.charAt(j)=='?')){ i++; j++; }else if(j<p.length() && p.charAt(j)=='*'){ sID=j; prevM=i; j++; }else if(sID!=-1){ j=sID+1; prevM++; i=prevM; }else{ return false; } } while(j<p.length() && p.charAt(j)=='*') j++; if(i!=s.length() || j!=p.leng"See full answer

    Software Engineer
    Coding
    +1 more
  • " function diffBetweenTwoStrings(source, target) { /** @param source: string @param target: string @return: string[] */ let dp = new Array(source.length+1).fill().map(() => Array(target.length+1).fill(0)) for (let i = source.length; i>= 0; i--) { for (let j = target.length; j>= 0; j--) { if (i === source.length) { dpi = target.length - j } else if (j === target.length) { dpi = sou"

    Matthew K. - " function diffBetweenTwoStrings(source, target) { /** @param source: string @param target: string @return: string[] */ let dp = new Array(source.length+1).fill().map(() => Array(target.length+1).fill(0)) for (let i = source.length; i>= 0; i--) { for (let j = target.length; j>= 0; j--) { if (i === source.length) { dpi = target.length - j } else if (j === target.length) { dpi = sou"See full answer

    Coding
    Data Structures & Algorithms
  • Meta (Facebook) logoAsked at Meta (Facebook) 

    "if decreasing arr, start from end and keep checking if next element increases by 1 or not. wherever not, put that value there."

    Rishabh R. - "if decreasing arr, start from end and keep checking if next element increases by 1 or not. wherever not, put that value there."See full answer

    Coding
    Data Structures & Algorithms
    +1 more
  • "The question is incomplete --- the code only passes if you return the data frame sorted by BOTH department name AND rank. While in the problem description, it mentions to only rank by department name: "The results should be ordered by department name." Not a big difference I know, but students shouldn't need to look into the solution to get the necessary knowledge to answer the question."

    Chao peter Y. - "The question is incomplete --- the code only passes if you return the data frame sorted by BOTH department name AND rank. While in the problem description, it mentions to only rank by department name: "The results should be ordered by department name." Not a big difference I know, but students shouldn't need to look into the solution to get the necessary knowledge to answer the question."See full answer

    Data Scientist
    Coding
    +2 more
  • Machine Learning 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
  • "simply check its size if the size if the size is greater than n then yes it has duplicate"

    Kunal kumar S. - "simply check its size if the size if the size is greater than n then yes it has duplicate"See full answer

    Machine Learning Engineer
    Coding
    +2 more
  • Software Engineer
    Coding
    +1 more
  • Gusto logoAsked at Gusto 
    Software Engineer
    Coding
Showing 261-280 of 344