Skip to main content

Coding Interview Questions

Review this list of 418 Coding interview questions and answers verified by hiring managers and candidates.
  • "public static char getRepeatingCharacterInGivenString(String str){ char result = '0'; HashSet set = new HashSet(); for(int i=0;i<str.length();i++){ char c = str.charAt(i); if(!set.contains(c)){ set.add(c); } else{ result= c; break; } } return result; }"

    Sravanthi M. - "public static char getRepeatingCharacterInGivenString(String str){ char result = '0'; HashSet set = new HashSet(); for(int i=0;i<str.length();i++){ char c = str.charAt(i); if(!set.contains(c)){ set.add(c); } else{ result= c; break; } } return result; }"See full answer

    QA Engineer
    Coding
    +1 more
  • Confluent logoAsked at Confluent 

    "This depends on the list of documents and the length of the documents. My implementation will use Trie with node containing the following: class TrieNode { is_end: boolean, instances: { docid → [wordpositions] }, children: array[26] } Look up for a word will give result instances{docid:wordposition...} dictionary (which can be further improved by methods like max instance on a document....you name it...) Trie space is proportional to the total characters in"

    Aelaf G. - "This depends on the list of documents and the length of the documents. My implementation will use Trie with node containing the following: class TrieNode { is_end: boolean, instances: { docid → [wordpositions] }, children: array[26] } Look up for a word will give result instances{docid:wordposition...} dictionary (which can be further improved by methods like max instance on a document....you name it...) Trie space is proportional to the total characters in"See full answer

    Software Engineer
    Coding
    +1 more
  • "Depend on the array size and number of 0's theere."

    Nasit S. - "Depend on the array size and number of 0's theere."See full answer

    Software Engineer
    Coding
    +1 more
  • Uber logoAsked at Uber 

    "Not my answer, but rather the details of this question. It should include the following functions: int insertNewCustomer(double revenue) -> returns a customer ID (assume auto-incremented & 0-based) int insertNewCustomer(double revenue, int referrerID) -> returns a customer ID (assume auto-incremented & 0-based) Set getLowestKCustomersByMinTotalRevenue(int k, double minTotalRevenue) -> returns customer IDs Note: The total revenue consists of the revenue that this customer bring"

    Anzhe M. - "Not my answer, but rather the details of this question. It should include the following functions: int insertNewCustomer(double revenue) -> returns a customer ID (assume auto-incremented & 0-based) int insertNewCustomer(double revenue, int referrerID) -> returns a customer ID (assume auto-incremented & 0-based) Set getLowestKCustomersByMinTotalRevenue(int k, double minTotalRevenue) -> returns customer IDs Note: The total revenue consists of the revenue that this customer bring"See full answer

    Data Engineer
    Coding
  • +1

    "too many questions for clarification on this to start"

    Steven S. - "too many questions for clarification on this to start"See full answer

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

  • +7

    "Another DFS approach, without storing all the distances from typing import List from collections import deque def shortestCellPath(grid: List[List[int]], sr: int, sc: int, tr: int, tc: int) -> int: n_rows = len(grid) n_cols = len(grid[0]) min_len = float("inf") stack = deque([(sr, sc, 0)]) # (x, y, distance) visited = set() while stack: currrow, currcol, curr_d = stack.pop() if (currrow, currcol) in visited: continue "

    Gabriele G. - "Another DFS approach, without storing all the distances from typing import List from collections import deque def shortestCellPath(grid: List[List[int]], sr: int, sc: int, tr: int, tc: int) -> int: n_rows = len(grid) n_cols = len(grid[0]) min_len = float("inf") stack = deque([(sr, sc, 0)]) # (x, y, distance) visited = set() while stack: currrow, currcol, curr_d = stack.pop() if (currrow, currcol) in visited: continue "See full answer

    Coding
    Data Structures & Algorithms
  • Solutions Architect
    Coding
  • +2

    "SELECT COUNT(*) unique_conversations FROM messenger_sends WHERE senderid < receiverid"

    Lucas G. - "SELECT COUNT(*) unique_conversations FROM messenger_sends WHERE senderid < receiverid"See full answer

    Coding
    SQL
  • 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
  • Visa logoAsked at Visa 
    Software Engineer
    Coding
    +1 more
  • Coding
    Data Structures & Algorithms
  • "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
  • Meta logoAsked at Meta 

    "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
  • Software Engineer
    Coding
    +1 more
  • +4

    "SELECT e1.empid AS manageremployee_id, e1.empname AS managername, COUNT(e2.empid) AS numberofdirectreports FROM employees AS e1 INNER JOIN employees AS e2 ON e2.managerid = e1.empid GROUP BY e1.emp_id HAVING COUNT(e2.emp_id) >= 2 ORDER BY numberofdirectreports DESC, managername ASC `"

    Alvin P. - "SELECT e1.empid AS manageremployee_id, e1.empname AS managername, COUNT(e2.empid) AS numberofdirectreports FROM employees AS e1 INNER JOIN employees AS e2 ON e2.managerid = e1.empid GROUP BY e1.emp_id HAVING COUNT(e2.emp_id) >= 2 ORDER BY numberofdirectreports DESC, managername ASC `"See full answer

    Coding
    SQL
  • Robinhood logoAsked at Robinhood 

    "Assuming that trades will have information like trade_type buy or sell trade_price with these tuples, one can iterate over each trade while maintaining a stack which maintains all the open buy trades. If we encounter a sell trade then we pop one element make it a buy/sell pair and calculate the profit/loss for that pair. Moreover, keep adding pair-wise profit/loss to calculate overall profit as we continue iterating over trades. At the end print pairs and their profit/loss along with"

    Parth S. - "Assuming that trades will have information like trade_type buy or sell trade_price with these tuples, one can iterate over each trade while maintaining a stack which maintains all the open buy trades. If we encounter a sell trade then we pop one element make it a buy/sell pair and calculate the profit/loss for that pair. Moreover, keep adding pair-wise profit/loss to calculate overall profit as we continue iterating over trades. At the end print pairs and their profit/loss along with"See full answer

    Coding
    Data Structures & Algorithms
    +1 more
  • Nvidia logoAsked at Nvidia 

    "def containSubString(mainString, SubString): s1 = "hello world" # main String s2 = "hello" s3 = "world" s4 = "Nothing" answer1 = containSubString(s1, s2) answer2 = containSubString(s1, s3) answer3 = containSubString(s1, s4) print(answer1 , answer2, answer) "

    Jalpa S. - "def containSubString(mainString, SubString): s1 = "hello world" # main String s2 = "hello" s3 = "world" s4 = "Nothing" answer1 = containSubString(s1, s2) answer2 = containSubString(s1, s3) answer3 = containSubString(s1, s4) print(answer1 , answer2, answer) "See full answer

    Software Engineer
    Coding
    +1 more
  • Nvidia logoAsked at Nvidia 

    "virtual function is a member function declared with virtual keyword in a base class. It enables derived classes to redefine this function with their own specific implementations."

    Sonia M. - "virtual function is a member function declared with virtual keyword in a base class. It enables derived classes to redefine this function with their own specific implementations."See full answer

    Software Engineer
    Coding
    +1 more
  • +4

    "function flattenDictionary(dict) { let output = {}; for (let key of Object.keys(dict)) { const value = dict[key]; if (typeof value !== 'object') { output[key] = value; } else { const childDict = flattenDictionary(value); for (let childKey of Object.keys(childDict)) { const filteredKey = key != "" && childKey !== "" ? ${key}.${childKey} : key != "" ? key : childKey; output[filteredKey] = childDict[childK"

    Tiago R. - "function flattenDictionary(dict) { let output = {}; for (let key of Object.keys(dict)) { const value = dict[key]; if (typeof value !== 'object') { output[key] = value; } else { const childDict = flattenDictionary(value); for (let childKey of Object.keys(childDict)) { const filteredKey = key != "" && childKey !== "" ? ${key}.${childKey} : key != "" ? key : childKey; output[filteredKey] = childDict[childK"See full answer

    Coding
    Data Structures & Algorithms
  • LinkedIn logoAsked at LinkedIn 

    "Currently, there's no option to write Python code for the solution to this problem. Is it possible to add it?"

    Abhishek V. - "Currently, there's no option to write Python code for the solution to this problem. Is it possible to add it?"See full answer

    Software Engineer
    Coding
    +1 more
Showing 261-280 of 418