Coding Interview Questions

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

    "#include #include using namespace std; int main() { int n; cin >> n; int a[n]; for(int i=0; i=0 and a[i]<=2) { sort(a[0], a[n]); } } cout << "After sorting array: "; for(int i=0; i<n; i++) { cout << a[i] << " "; } }"

    Shaxboz A. - "#include #include using namespace std; int main() { int n; cin >> n; int a[n]; for(int i=0; i=0 and a[i]<=2) { sort(a[0], a[n]); } } cout << "After sorting array: "; for(int i=0; i<n; i++) { cout << a[i] << " "; } }"See full answer

    Coding
    Data Structures & Algorithms
    +1 more
  • Google Cloud (GCP) logoAsked at Google Cloud (GCP) 

    "(Like a Rummy Game) There are 3 colors of tiles. Each tile has a number 1-9 on it. So the 27-tile set makes a deck. There are 4 decks. (Total = 108 tiles) Tile Colors = {Red, Black, Green} The tiles could be grouped together in patterns Types of patterns : The three tiles are identical (R2, R2, R2) The three tiles are of same color and sequential (R2, R3, R4). Sequence cannot be overlapping (R8, R9, R1 is not a pattern) Help : Tile Notations - R2 denotes Red tile having num 2 A player"

    Gopal D. - "(Like a Rummy Game) There are 3 colors of tiles. Each tile has a number 1-9 on it. So the 27-tile set makes a deck. There are 4 decks. (Total = 108 tiles) Tile Colors = {Red, Black, Green} The tiles could be grouped together in patterns Types of patterns : The three tiles are identical (R2, R2, R2) The three tiles are of same color and sequential (R2, R3, R4). Sequence cannot be overlapping (R8, R9, R1 is not a pattern) Help : Tile Notations - R2 denotes Red tile having num 2 A player"See full answer

    Software Engineer
    Coding
  • "Run length encoding. This will preserve order of values in vector."

    Yash S. - "Run length encoding. This will preserve order of values in vector."See full answer

    Coding
    Data Structures & Algorithms
    +1 more
  • Software Engineer
    Coding
    +1 more
  • LinkedIn logoAsked at LinkedIn 
    Software Engineer
    Coding
    +2 more
  • 🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.

  • Adobe logoAsked at Adobe 

    "#include #include #include using namespace std; void printComs(int prev, int start, int end, int target) { if (start >= end) return; while (start target) { end--; } else { st"

    Iris F. - "#include #include #include using namespace std; void printComs(int prev, int start, int end, int target) { if (start >= end) return; while (start target) { end--; } else { st"See full answer

    Software Engineer
    Coding
    +4 more
  • Apple logoAsked at Apple 

    "filter function usually exists in some high level programming that adopt FP paradigm. It taks a sequence of items and a predicate function, and returns (conceptually) a subset of the items that satisfy the predicate. Adopt this kind of operation (filter, map, reduce, take, pairwise ...) can help writting cleaner code, and reduce the usage of mutable part in the program, lower the possibility of making human mistake. Take Python for example (although const-ness is not exists in Python), assu"

    Weida H. - "filter function usually exists in some high level programming that adopt FP paradigm. It taks a sequence of items and a predicate function, and returns (conceptually) a subset of the items that satisfy the predicate. Adopt this kind of operation (filter, map, reduce, take, pairwise ...) can help writting cleaner code, and reduce the usage of mutable part in the program, lower the possibility of making human mistake. Take Python for example (although const-ness is not exists in Python), assu"See full answer

    Software Engineer
    Coding
    +1 more
  • "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
  • 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
  • Apple logoAsked at Apple 
    Software Engineer
    Coding
    +1 more
  • "import java.util.*; public class NetworkTopology { public int topologytype(int N, int M, int[] input3, int[] input4) { if (M != N - 1 && M != N) return -1; // Fast check for invalid cases int[] degree = new int[N + 1]; // Degree of each node (1-based indexing) // Build the degree array for (int i = 0; i < M; i++) { degree[input3[i]]++; degree[input4[i]]++; } // Check for Bus Topology boolean isBus = (M"

    Alessandro R. - "import java.util.*; public class NetworkTopology { public int topologytype(int N, int M, int[] input3, int[] input4) { if (M != N - 1 && M != N) return -1; // Fast check for invalid cases int[] degree = new int[N + 1]; // Degree of each node (1-based indexing) // Build the degree array for (int i = 0; i < M; i++) { degree[input3[i]]++; degree[input4[i]]++; } // Check for Bus Topology boolean isBus = (M"See full answer

    Software Engineer
    Coding
    +1 more
  • Apple logoAsked at Apple 
    Software Engineer
    Coding
    +1 more
  • Salesforce logoAsked at Salesforce 
    Software Engineer
    Coding
    +1 more
  • 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
  • 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
  • "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
  • " 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
  • " 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
Showing 341-360 of 382