Coding Interview Questions

Review this list of 374 coding interview questions and answers verified by hiring managers and candidates.
  • "class Node { int val; Node left, right; Node(int v) { val = v; left = right = null; } } class BinaryTree { Node root1, root2; boolean identicalTrees(Node a, Node b) { if (a == null && b == null) return true; if (a != null && b != null) return (a.val == b.val && identicalTrees(a.left, b.left) && identicalTrees(a.right, b.right)); "

    Tushar A. - "class Node { int val; Node left, right; Node(int v) { val = v; left = right = null; } } class BinaryTree { Node root1, root2; boolean identicalTrees(Node a, Node b) { if (a == null && b == null) return true; if (a != null && b != null) return (a.val == b.val && identicalTrees(a.left, b.left) && identicalTrees(a.right, b.right)); "See full answer

    Coding
    Data Structures & Algorithms
  • Oracle logoAsked at Oracle 

    "def countuniqueoutfits(totalpants: int, uniquepants: int, totalshirts: int, uniqueshirts: int, totalhats: int, uniquehats: int) -> int: """ Number of unique outfits can simply be defined by (uniquepantschoose1uniqueshirtschoose1uniquehatschoose_1) (uniquepantschoose1*uniqueshirtschoose1) # Not wearing a hat nchoosek is n """ res = (uniquepants*uniqueshirtsuniquehats) + (uniquepantsunique_shirts) return res print(countuniqueoutfits(2, 1, 1, 1, 3, 2))"

    Sai R. - "def countuniqueoutfits(totalpants: int, uniquepants: int, totalshirts: int, uniqueshirts: int, totalhats: int, uniquehats: int) -> int: """ Number of unique outfits can simply be defined by (uniquepantschoose1uniqueshirtschoose1uniquehatschoose_1) (uniquepantschoose1*uniqueshirtschoose1) # Not wearing a hat nchoosek is n """ res = (uniquepants*uniqueshirtsuniquehats) + (uniquepantsunique_shirts) return res print(countuniqueoutfits(2, 1, 1, 1, 3, 2))"See full answer

    Data Scientist
    Coding
  • Apple logoAsked at Apple 
    Software Engineer
    Coding
    +1 more
  • Apple logoAsked at Apple 
    Software Engineer
    Coding
    +1 more
  • " import pandas as pd from datetime import datetime def findfastestlike(log: pd.DataFrame) -> pd.DataFrame: log=log.sortvalues(['userid','timestamp']) #get the prev event, time by user log['prevevent'] = log.groupby('userid')['event'].shift(1) log['prevtimestamp'] = log.groupby('userid')['timestamp'].shift(1) True only on rows where the previous event was a login and the current event is a like log['loginlike'] = (log['prevevent'] == 'log"

    Sean L. - " import pandas as pd from datetime import datetime def findfastestlike(log: pd.DataFrame) -> pd.DataFrame: log=log.sortvalues(['userid','timestamp']) #get the prev event, time by user log['prevevent'] = log.groupby('userid')['event'].shift(1) log['prevtimestamp'] = log.groupby('userid')['timestamp'].shift(1) True only on rows where the previous event was a login and the current event is a like log['loginlike'] = (log['prevevent'] == 'log"See full answer

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

  • " debug your code below departments = pd.DataFrame({ 'id': [1, 2, 3, 4, 5], 'name': ['Reporting', 'Engineering', 'Marketing', 'Biz Dev', 'Silly Walks'] }) employees = pd.DataFrame({ 'id': [1, 2, 3, 4, 5, 6], 'first_name': ['John', 'Ava', 'Cailin', 'Mike', 'Ian', 'John'], 'last_name': ['Smith', 'Muffinson', 'Ninson', 'Peterson', 'Peterson', 'Mills'], 'salary': [20000, 10000, 30000, 20000, 80000, 50000], 'department_id': [1, 5, 2, 2, 2, 3] }) projects = p"

    Sean L. - " debug your code below departments = pd.DataFrame({ 'id': [1, 2, 3, 4, 5], 'name': ['Reporting', 'Engineering', 'Marketing', 'Biz Dev', 'Silly Walks'] }) employees = pd.DataFrame({ 'id': [1, 2, 3, 4, 5, 6], 'first_name': ['John', 'Ava', 'Cailin', 'Mike', 'Ian', 'John'], 'last_name': ['Smith', 'Muffinson', 'Ninson', 'Peterson', 'Peterson', 'Mills'], 'salary': [20000, 10000, 30000, 20000, 80000, 50000], 'department_id': [1, 5, 2, 2, 2, 3] }) projects = p"See full answer

    Data Analyst
    Coding
    +1 more
  • Apple logoAsked at Apple 
    Software Engineer
    Coding
    +1 more
  • "public class BoggleBoard { public static List findWords(char board, Set dictionary) { int rows = board.length; int cols = board[0].length; boolean visited = new booleanrows; int directions = {{1,0}, {-1,0}, {0,1}, {0,-1}}; List result = new ArrayList(); for(int i=0; i<rows; i++) { for(int j=0; j<cols; j++) { dfs(board, visited, i, j, dictionary, "", result, dire"

    Aniket G. - "public class BoggleBoard { public static List findWords(char board, Set dictionary) { int rows = board.length; int cols = board[0].length; boolean visited = new booleanrows; int directions = {{1,0}, {-1,0}, {0,1}, {0,-1}}; List result = new ArrayList(); for(int i=0; i<rows; i++) { for(int j=0; j<cols; j++) { dfs(board, visited, i, j, dictionary, "", result, dire"See full answer

    Software Engineer
    Coding
    +1 more
  • Adobe logoAsked at Adobe 

    "import java.util.Arrays; import java.util.stream.Collectors; class Main { // Recursive function to print all combinations of numbers from \i\ to \n\ // having sum \n. The index\ denotes the next free slot in the output array \out\ public static void printCombinations(int i, int n, int[] out, int index) { // if the sum becomes n, print the combination if (n == 0) { System.out.println(Arrays.stream(out).limit(index) .boxed().collect(Collectors.toList())); } // start from the previous e"

    Relynn may silver B. - "import java.util.Arrays; import java.util.stream.Collectors; class Main { // Recursive function to print all combinations of numbers from \i\ to \n\ // having sum \n. The index\ denotes the next free slot in the output array \out\ public static void printCombinations(int i, int n, int[] out, int index) { // if the sum becomes n, print the combination if (n == 0) { System.out.println(Arrays.stream(out).limit(index) .boxed().collect(Collectors.toList())); } // start from the previous e"See full answer

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

    "function constructTree(n, matrix) { let parent = []; let child = []; let root = null; for (let i = 0; i < n; i++) { for (let j = 0; j < n; j++) { if (matrixi === 1) { parent.push(i); child.push(j); } } } for (let i = 0; i < n; i++) { if (parent.indexOf(i) === -1) { root = i; } } let node = new Node(root); for (let i = 0; i < n; i++) { if (i !== root) { constructTreeUtil(node, parent[i], child[i]); } } return node; }"

    Ugo C. - "function constructTree(n, matrix) { let parent = []; let child = []; let root = null; for (let i = 0; i < n; i++) { for (let j = 0; j < n; j++) { if (matrixi === 1) { parent.push(i); child.push(j); } } } for (let i = 0; i < n; i++) { if (parent.indexOf(i) === -1) { root = i; } } let node = new Node(root); for (let i = 0; i < n; i++) { if (i !== root) { constructTreeUtil(node, parent[i], child[i]); } } return node; }"See full answer

    Coding
    Data Structures & Algorithms
    +1 more
  • "I got it right"

    Rudransh V. - "I got it right"See full answer

    Software Engineer
    Coding
    +1 more
  • Machine Learning Engineer
    Coding
    +1 more
  • Adobe logoAsked at Adobe 
    Video answer for 'Print all possible solutions to the N-Queens problem.'
    Data Engineer
    Coding
    +2 more
  • Software Engineer
    Coding
    +1 more
  • "Binary serach on E range"

    Shikha S. - "Binary serach on E range"See full answer

    Software Engineer
    Coding
    +1 more
  • Bolt logoAsked at Bolt 
    Software Engineer
    Coding
    +1 more
Showing 341-360 of 374