Coding Interview Questions

Review this list of 363 coding interview questions and answers verified by hiring managers and candidates.
  • +8

    "with my_table as (select * , rownumber() over(order by customerid) as row_index from customers) select customer_id, customer_name from my_table where row_index % 3 = 0"

    Marcos G. - "with my_table as (select * , rownumber() over(order by customerid) as row_index from customers) select customer_id, customer_name from my_table where row_index % 3 = 0"See full answer

    Coding
    SQL
  • "Let’s say the matrix is m x n (i.e., m rows and n columns). Start from the top-right corner of the matrix. Move left if you see a 1. Move down if you see a 0. Keep track of the row index where you last saw the leftmost 1 — that row has the most 1s. public class MaxOnesRow { public static int rowWithMostOnes(int matrix) { int rows = matrix.length; int cols = matrix[0].length; int maxRowIndex = -1; int j = cols - 1; /"

    Khushbu R. - "Let’s say the matrix is m x n (i.e., m rows and n columns). Start from the top-right corner of the matrix. Move left if you see a 1. Move down if you see a 0. Keep track of the row index where you last saw the leftmost 1 — that row has the most 1s. public class MaxOnesRow { public static int rowWithMostOnes(int matrix) { int rows = matrix.length; int cols = matrix[0].length; int maxRowIndex = -1; int j = cols - 1; /"See full answer

    Software Engineer
    Coding
    +1 more
  • +5

    "Select interface, Count(case when issuccessfulpost then 1 end) as post_success, Count() as postattempt, ROUND((COUNT(CASE WHEN issuccessfulpost THEN 1 END) * 100 / COUNT()), 2) AS postsuccess_rate from post where interface like 'Iphone%' group by 1 order by postsuccessrate desc `"

    Richard B. - "Select interface, Count(case when issuccessfulpost then 1 end) as post_success, Count() as postattempt, ROUND((COUNT(CASE WHEN issuccessfulpost THEN 1 END) * 100 / COUNT()), 2) AS postsuccess_rate from post where interface like 'Iphone%' group by 1 order by postsuccessrate desc `"See full answer

    Coding
    SQL
  • Google logoAsked at Google 

    "def split_count(s): return 2**(len(s)-1) `"

    Steve M. - "def split_count(s): return 2**(len(s)-1) `"See full answer

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

  • Meta (Facebook) logoAsked at Meta (Facebook) 

    "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
  • "Was given 90 minutes with an exhaustive set of requirements to be implemented as a full-stack coding exercise. It was supposed to have a UX, a server and a database to store and retrieve data. The IDE was supposed to be self-setup before the interview. The panel asked questions on top of the implementation around decision making from a technical perspective"

    Aman G. - "Was given 90 minutes with an exhaustive set of requirements to be implemented as a full-stack coding exercise. It was supposed to have a UX, a server and a database to store and retrieve data. The IDE was supposed to be self-setup before the interview. The panel asked questions on top of the implementation around decision making from a technical perspective"See full answer

    Software Engineer
    Coding
  • Google logoAsked at Google 
    +3

    "import time class Task: def init\(self, description, interval=None): self.description = description self.interval = interval self.next_run = time.time() class SimpleTaskScheduler: def init\(self): self.tasks = [] def add_task(self, description, interval=None): self.tasks.append(Task(description, interval)) def run(self, duration=60): end_time = time.time() + duration while time.time() < end_time: curr"

    Yash N. - "import time class Task: def init\(self, description, interval=None): self.description = description self.interval = interval self.next_run = time.time() class SimpleTaskScheduler: def init\(self): self.tasks = [] def add_task(self, description, interval=None): self.tasks.append(Task(description, interval)) def run(self, duration=60): end_time = time.time() + duration while time.time() < end_time: curr"See full answer

    Machine Learning Engineer
    Coding
    +1 more
  • Meta (Facebook) logoAsked at Meta (Facebook) 
    +1

    "my answer: void* memcpy(void* dest, const void* src, size_t n) { unsigned char* uDest = static_cast(dest); const unsigned char* ucSrc = static_cast(src); for(size_t i= 0; i(dest); const unsigned c"

    Srihitha J. - "my answer: void* memcpy(void* dest, const void* src, size_t n) { unsigned char* uDest = static_cast(dest); const unsigned char* ucSrc = static_cast(src); for(size_t i= 0; i(dest); const unsigned c"See full answer

    Software Engineer
    Coding
    +1 more
  • "Here is my first shot at it. Please excuse formatting. To find the maximum depth of the dependencies given a list of nodes, each having a unique string id and a list of subnodes it depends on, you can perform a depth-first search (DFS) to traverse the dependency graph. Here's how you can implement this: Represent the nodes and their dependencies using a dictionary. Perform a DFS on each node to find the maximum depth of the dependencies. Keep track of the maximum depth encountered dur"

    Tes d H. - "Here is my first shot at it. Please excuse formatting. To find the maximum depth of the dependencies given a list of nodes, each having a unique string id and a list of subnodes it depends on, you can perform a depth-first search (DFS) to traverse the dependency graph. Here's how you can implement this: Represent the nodes and their dependencies using a dictionary. Perform a DFS on each node to find the maximum depth of the dependencies. Keep track of the maximum depth encountered dur"See full answer

    Software Engineer
    Coding
    +1 more
  • +7

    "WITH high_score AS( SELECT player_id, MAX(gamescore) AS maxscore FROM scores GROUP BY player_id ), rankings AS( SELECT p.player_name, p.team_id, max_score, DENSERANK() OVER(PARTITION BY p.teamid ORDER BY h.maxscore DESC) AS scorerank FROM high_score AS h JOIN players AS p USING(player_id) ) SELECT team_id, player_name, max_score FROM rankings WHERE score_rank <= 2 GROUP BY teamid, playername O"

    Alvin P. - "WITH high_score AS( SELECT player_id, MAX(gamescore) AS maxscore FROM scores GROUP BY player_id ), rankings AS( SELECT p.player_name, p.team_id, max_score, DENSERANK() OVER(PARTITION BY p.teamid ORDER BY h.maxscore DESC) AS scorerank FROM high_score AS h JOIN players AS p USING(player_id) ) SELECT team_id, player_name, max_score FROM rankings WHERE score_rank <= 2 GROUP BY teamid, playername O"See full answer

    Coding
    SQL
  • Machine Learning Engineer
    Coding
    +3 more
  • Apple logoAsked at Apple 
    +4

    "public static void sortBinaryArray(int[] array) { int len = array.length; int[] res = new int[len]; int r=len-1; for (int value : array) { if(value==1){ res[r]= 1; r--; } } System.out.println(Arrays.toString(res)); } `"

    Nitin P. - "public static void sortBinaryArray(int[] array) { int len = array.length; int[] res = new int[len]; int r=len-1; for (int value : array) { if(value==1){ res[r]= 1; r--; } } System.out.println(Arrays.toString(res)); } `"See full answer

    Software Engineer
    Coding
    +1 more
  • Meta (Facebook) logoAsked at Meta (Facebook) 

    "Problem: Given a modified binary tree, where each node also has a pointer to it's parent, find the first common ancestor of two nodes. Answer: As it happens, the structure that we're looking at is actually a linked list (one pointer up), so the problem is identical to trying to find if two linked lists share a common node. How this works is by stacking the two chains of nodes together so they're the same length. chain1 = node1 chain2= node2 while True: chain1 = chain1.next chain2=chain"

    Michael B. - "Problem: Given a modified binary tree, where each node also has a pointer to it's parent, find the first common ancestor of two nodes. Answer: As it happens, the structure that we're looking at is actually a linked list (one pointer up), so the problem is identical to trying to find if two linked lists share a common node. How this works is by stacking the two chains of nodes together so they're the same length. chain1 = node1 chain2= node2 while True: chain1 = chain1.next chain2=chain"See full answer

    Machine Learning Engineer
    Coding
    +1 more
  • Adobe logoAsked at Adobe 
    Data Engineer
    Coding
    +4 more
  • +16

    "def validateIP(ip): """ @param ip: str @return: bool """ \# ip needs to be in X.X.X.X \# X is from 0 to 255 \# split the ip at "." split = ip.split('.') if (len(split) != 4): return False for number in split: if (int(number) 255): return False return True"

    Anonymous Owl - "def validateIP(ip): """ @param ip: str @return: bool """ \# ip needs to be in X.X.X.X \# X is from 0 to 255 \# split the ip at "." split = ip.split('.') if (len(split) != 4): return False for number in split: if (int(number) 255): return False return True"See full answer

    Coding
    Data Structures & Algorithms
  • +6

    "Here is my implementation: select marketing_channel, AVG(purchasevalue) as avgpurchase_value from attribution group by marketing_channel order by avgpurchasevalue DESC ; There is no need to copy and past the line of code for calculating the average into order by, just Alias is enough because going by the order of execution in sql, Always, order by is executed after executing select clause."

    Maliki U. - "Here is my implementation: select marketing_channel, AVG(purchasevalue) as avgpurchase_value from attribution group by marketing_channel order by avgpurchasevalue DESC ; There is no need to copy and past the line of code for calculating the average into order by, just Alias is enough because going by the order of execution in sql, Always, order by is executed after executing select clause."See full answer

    Coding
    SQL
  • +10

    "select sub.name subreddit_name, count(distinct us.userid) totalusers from user_subreddit as us left join subreddit as sub on us.subredditid = sub.subredditid group by us.subreddit_id having count(distinct us.user_id) > 3"

    Lucas G. - "select sub.name subreddit_name, count(distinct us.userid) totalusers from user_subreddit as us left join subreddit as sub on us.subredditid = sub.subredditid group by us.subreddit_id having count(distinct us.user_id) > 3"See full answer

    Coding
    SQL
  • +13

    "function insertItem(heap, item) { heap.push(item); if (heap.length > 0) { let current = heap.length - 1; while(current > 0 && heap[Math.floor(current/2)] > heap[current]) { [heap[Math.floor(current/2)], heap[current]] = [heap[current], heap[Math.floor(current/2)]]; current = Math.floor(current/2); } } } function extractMin(heap) { let smallest = heap[0]; let len = heap.length; if (len > 2) { heap[0] = heap[len - 1]; heap.splice(len - 1); "

    Arturo Z. - "function insertItem(heap, item) { heap.push(item); if (heap.length > 0) { let current = heap.length - 1; while(current > 0 && heap[Math.floor(current/2)] > heap[current]) { [heap[Math.floor(current/2)], heap[current]] = [heap[current], heap[Math.floor(current/2)]]; current = Math.floor(current/2); } } } function extractMin(heap) { let smallest = heap[0]; let len = heap.length; if (len > 2) { heap[0] = heap[len - 1]; heap.splice(len - 1); "See full answer

    Coding
    Data Structures & Algorithms
  • Adobe logoAsked at Adobe 
    +3

    "Should this question be BST, not just BT? Otherwise it would not be possible to reconstruct the tree solely based on the array regardless of its order"

    TreeOfWisdom - "Should this question be BST, not just BT? Otherwise it would not be possible to reconstruct the tree solely based on the array regardless of its order"See full answer

    Software Engineer
    Coding
    +2 more
Showing 141-160 of 363