Coding Interview Questions

Review this list of 137 interview questions and answers verified by hiring managers and candidates.
  • Adobe logoAsked at Adobe 
    +37

    "function twoSum(nums, target) { let complements = new Map(); for (let i = 0; i < nums.length; i++) { let diff = target - nums[i]; if (complements.has(diff)) { return [complements.get(diff), i]; } complements.set(nums[i], i); } return []; } console.log(twoSum([2, 7, 11, 15], 9)); `"

    Jean-pierre C. - "function twoSum(nums, target) { let complements = new Map(); for (let i = 0; i < nums.length; i++) { let diff = target - nums[i]; if (complements.has(diff)) { return [complements.get(diff), i]; } complements.set(nums[i], i); } return []; } console.log(twoSum([2, 7, 11, 15], 9)); `"See full answer

    Software Engineer
    Data Structures & Algorithms
    +5 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
  • Adobe logoAsked at Adobe 
    Video answer for 'Generate Parentheses'
    +5

    "function generateParentheses(n) { if (n < 1) { return []; } if (n === 1) { return ["()"]; } const combinations = new Set(); let previousCombinations = generateParentheses(n-1); for (let prev of previousCombinations) { for (let i=0; i < prev.length; i++) { combinations.add(prev.slice(0, i+1) + "()" + prev.slice(i+1)); } } return [...combinations]; } `"

    Tiago R. - "function generateParentheses(n) { if (n < 1) { return []; } if (n === 1) { return ["()"]; } const combinations = new Set(); let previousCombinations = generateParentheses(n-1); for (let prev of previousCombinations) { for (let i=0; i < prev.length; i++) { combinations.add(prev.slice(0, i+1) + "()" + prev.slice(i+1)); } } return [...combinations]; } `"See full answer

    Software Engineer
    Data Structures & Algorithms
    +3 more
  • 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
    Data Structures & Algorithms
    +1 more
  • +7

    "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
  • 🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.

  • +16

    "def check_byte(octet): _""" Checks if the given string \octet\ represents a valid byte (0-255). """_ Check for empty string if not octet: return False Check if the string has non-digit characters if not octet.isdigit(): return False Check for leading zeroes in multi-digit numbers if len(octet) > 1 and octet[0] == '0': return False Check if the integer value is between 0 and 255 return 0 <= int(octet) <= 255 def va"

    Robert W. - "def check_byte(octet): _""" Checks if the given string \octet\ represents a valid byte (0-255). """_ Check for empty string if not octet: return False Check if the string has non-digit characters if not octet.isdigit(): return False Check for leading zeroes in multi-digit numbers if len(octet) > 1 and octet[0] == '0': return False Check if the integer value is between 0 and 255 return 0 <= int(octet) <= 255 def va"See full answer

    Data Structures & Algorithms
    Coding
  • +6

    "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
  • 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
    Data Structures & Algorithms
    +2 more
  • +13

    "function swap(arr, i, j) { const temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } function sortKMessedArray(arr, k) { for (let i=0; i < arr.length; i++) { for (let j=1; j <= k; j++) { if (arr[i+j] < arr[i]) { swap(arr, i, i+j); } } } return arr; } `"

    Tiago R. - "function swap(arr, i, j) { const temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } function sortKMessedArray(arr, k) { for (let i=0; i < arr.length; i++) { for (let j=1; j <= k; j++) { if (arr[i+j] < arr[i]) { swap(arr, i, i+j); } } } return arr; } `"See full answer

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

    "Problem Statement: The Fibonacci sequence is defined as F(n) = F(n-1) + F(n-2) with F(0) = 1 and F(1) = 1. The solution is given in the problem statement itself. If the value of n = 0, return 1. If the value of n = 1, return 1. Otherwise, return the sum of data at (n - 1) and (n - 2). Explanation: The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, typically starting with 0 and 1. Java Solution: public static int fib(int n"

    Rishi G. - "Problem Statement: The Fibonacci sequence is defined as F(n) = F(n-1) + F(n-2) with F(0) = 1 and F(1) = 1. The solution is given in the problem statement itself. If the value of n = 0, return 1. If the value of n = 1, return 1. Otherwise, return the sum of data at (n - 1) and (n - 2). Explanation: The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, typically starting with 0 and 1. Java Solution: public static int fib(int n"See full answer

    Software Engineer
    Data Structures & Algorithms
    +2 more
  • +3

    "-- The text of the task is a bit confusing. If the status is repeated several -- times, then in the end you should show as start_date the date of the first -- occurrence, and in end_date the date of the last occurrence of this status, -- and not the date of the beginning of the next status with t1 as (select order_id, status, orderdate as startdate, lead(orderdate) over (partition by orderid order by orderdate) as enddate, ifnull(lag(status) over (partition by order_id order by or"

    Alexey T. - "-- The text of the task is a bit confusing. If the status is repeated several -- times, then in the end you should show as start_date the date of the first -- occurrence, and in end_date the date of the last occurrence of this status, -- and not the date of the beginning of the next status with t1 as (select order_id, status, orderdate as startdate, lead(orderdate) over (partition by orderid order by orderdate) as enddate, ifnull(lag(status) over (partition by order_id order by or"See full answer

    Coding
    SQL
  • +9

    "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
  • +5

    "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
  • +2

    "-- LTV = Sum of all purchases made by that user -- order the results by desc on LTV select u.user_id, sum(a.purchase_value) as LTV from user_sessions u join attribution a on u.sessionid = a.sessionid group by u.user_id order by sum(a.purchase_value) desc"

    Mohit C. - "-- LTV = Sum of all purchases made by that user -- order the results by desc on LTV select u.user_id, sum(a.purchase_value) as LTV from user_sessions u join attribution a on u.sessionid = a.sessionid group by u.user_id order by sum(a.purchase_value) desc"See full answer

    Coding
    SQL
  • +4

    "SELECT order_amount FROM ( SELECT *, rank() OVER(ORDER BY order_amount desc) as ranking FROM departments d LEFT JOIN orders o ON d.departmentid = o.departmentid LEFT JOIN customers c ON o.customerid = c.customerid WHERE department_name = 'Fashion' ) where ranking = 2"

    Jacky T. - "SELECT order_amount FROM ( SELECT *, rank() OVER(ORDER BY order_amount desc) as ranking FROM departments d LEFT JOIN orders o ON d.departmentid = o.departmentid LEFT JOIN customers c ON o.customerid = c.customerid WHERE department_name = 'Fashion' ) where ranking = 2"See full answer

    Coding
    SQL
  • +5

    "select customer_id, order_date, orderid as earliestorder_id from ( select customer_id, order_date, order_id, rownumber() over (partition by customerid, orderdate order by orderdate) as orderrankper_customer from orders ) sub_table where orderrankper_customer=1 order by orderdate, customerid; Standard solution assumed that the orderid indicates which order comes in first. However this is not always the case, and sometime orderid can be random number withou"

    Jessica C. - "select customer_id, order_date, orderid as earliestorder_id from ( select customer_id, order_date, order_id, rownumber() over (partition by customerid, orderdate order by orderdate) as orderrankper_customer from orders ) sub_table where orderrankper_customer=1 order by orderdate, customerid; Standard solution assumed that the orderid indicates which order comes in first. However this is not always the case, and sometime orderid can be random number withou"See full answer

    Coding
    SQL
  • Adobe logoAsked at Adobe 
    Video answer for 'Merge k sorted linked lists.'
    +6

    "A much better solution than the one in the article, below: It looks like the ones writing articles here in Javascript do not understand the time/space complexity of javascript methods. shift, splice, sort, etc... In the solution article you have a shift and a sort being done inside a while, that is, the multiplication of Ns. My solution, below, iterates through the list once and then sorts it, separately. It´s O(N+Log(N)) class ListNode { constructor(val = 0, next = null) { th"

    Guilherme F. - "A much better solution than the one in the article, below: It looks like the ones writing articles here in Javascript do not understand the time/space complexity of javascript methods. shift, splice, sort, etc... In the solution article you have a shift and a sort being done inside a while, that is, the multiplication of Ns. My solution, below, iterates through the list once and then sorts it, separately. It´s O(N+Log(N)) class ListNode { constructor(val = 0, next = null) { th"See full answer

    Software Engineer
    Data Structures & Algorithms
    +4 more
  • +3

    "-- filter for december and november data -- the total order amount per depatment per month -- department, month, order_amount with monthly_orders AS ( SELECT department_id, strftime('%m', order_date) AS month, SUM(orderamount) AS orderamount FROM orders WHERE orderdate >= '2022-11-01' AND orderdate < '2023-01-01' group by department_id, month ), -- -- add difference from this month to last ( use lag ) monthly_comp"

    Aneesha K. - "-- filter for december and november data -- the total order amount per depatment per month -- department, month, order_amount with monthly_orders AS ( SELECT department_id, strftime('%m', order_date) AS month, SUM(orderamount) AS orderamount FROM orders WHERE orderdate >= '2022-11-01' AND orderdate < '2023-01-01' group by department_id, month ), -- -- add difference from this month to last ( use lag ) monthly_comp"See full answer

    Coding
    SQL
  • Google logoAsked at Google 
    +7

    "function areSentencesSimilar(sentence1, sentence2, similarPairs) { if (sentence1.length !== sentence2.length) return false; for (let i=0; i (w1 === word1 && !visited.has(w2)) || (w2 === word1 && !visited.has(w1))); if (!edge) { "

    Tiago R. - "function areSentencesSimilar(sentence1, sentence2, similarPairs) { if (sentence1.length !== sentence2.length) return false; for (let i=0; i (w1 === word1 && !visited.has(w2)) || (w2 === word1 && !visited.has(w1))); if (!edge) { "See full answer

    Software Engineer
    Data Structures & Algorithms
    +2 more
  • +1

    "SELECT AVG(julianday(dateend) - julianday(datestart)) AS avgcampaignduration FROM campaign; `"

    Salome L. - "SELECT AVG(julianday(dateend) - julianday(datestart)) AS avgcampaignduration FROM campaign; `"See full answer

    Coding
    SQL
Showing 61-80 of 137