Coding Interview Questions

Review this list of 344 coding interview questions and answers verified by hiring managers and candidates.
  • Adobe logoAsked at Adobe 
    +24

    "In python def find_duplicates(arr1: List[int], arr2: List[int]) -> List[int]: result = list(set(arr1) & set(arr2)) return result "

    Sammy R. - "In python def find_duplicates(arr1: List[int], arr2: List[int]) -> List[int]: result = list(set(arr1) & set(arr2)) return result "See full answer

    Data Engineer
    Coding
    +2 more
  • +6

    "with cte as (select (count(postid)/count(userid)) as avgpost, avg(issuccessfulpost) as avgsuccess from post) select p.userid,sum(issuccessfulpost) as postsuccess,count(p.postid) as postattempt,ROUND(avg(issuccessfulpost),2) as postsuccessrate from post p,cte c on p.user_id group by p.user_id having postattempt>c.avgpost and postsuccessrate<c.avg_success order by postsuccessrate desc"

    Devanshu K. - "with cte as (select (count(postid)/count(userid)) as avgpost, avg(issuccessfulpost) as avgsuccess from post) select p.userid,sum(issuccessfulpost) as postsuccess,count(p.postid) as postattempt,ROUND(avg(issuccessfulpost),2) as postsuccessrate from post p,cte c on p.user_id group by p.user_id having postattempt>c.avgpost and postsuccessrate<c.avg_success order by postsuccessrate desc"See full answer

    Data Scientist
    Coding
    +1 more
  • Amazon logoAsked at Amazon 

    "1) select avg(session) from table where session> 180 2) select round(sessiontime/300)*300 as sessionbin, count() as sessioncount from table group by round(sessiontime/300)300 order by session_bin 3) SELECT t1.country AS country_a, t2.country AS country_b FROM ( SELECT country, COUNT(*) AS session_count FROM yourtablename GROUP BY country ) AS t1 JOIN ( SELECT country, COUNT(*) AS session_count FROM yourtablename `GROUP BY countr"

    Erjan G. - "1) select avg(session) from table where session> 180 2) select round(sessiontime/300)*300 as sessionbin, count() as sessioncount from table group by round(sessiontime/300)300 order by session_bin 3) SELECT t1.country AS country_a, t2.country AS country_b FROM ( SELECT country, COUNT(*) AS session_count FROM yourtablename GROUP BY country ) AS t1 JOIN ( SELECT country, COUNT(*) AS session_count FROM yourtablename `GROUP BY countr"See full answer

    Data Scientist
    Coding
    +3 more
  • Google logoAsked at Google 
    Video answer for 'Write functions to serialize and deserialize a list of strings.'
    +4

    "function serialize(list) { for (let i=0; i 0xFFFF) { throw new Exception(String ${list[i]} is too long!); } const prefix = String.fromCharCode(length); list[i] = ${prefix}${list[i]}; console.log(list[i]) } return list.join(''); } function deserialize(s) { let i=0; const length = s.length; const output = []; while (i < length) { "

    Tiago R. - "function serialize(list) { for (let i=0; i 0xFFFF) { throw new Exception(String ${list[i]} is too long!); } const prefix = String.fromCharCode(length); list[i] = ${prefix}${list[i]}; console.log(list[i]) } return list.join(''); } function deserialize(s) { let i=0; const length = s.length; const output = []; while (i < length) { "See full answer

    Software Engineer
    Coding
    +1 more
  • Microsoft logoAsked at Microsoft 

    "You are given a string S and a number K as input, and your task is to print S to console output considering that, at most, you can print K characters per line. Example: S = "abracadabra sample" K = 11 Output: abracadabra sample Note that this problem requires the interviewee gather extra requirements from the interviewer (e.g. do we care about multiple white spaces? what if the length of a word is greater than K, ...)"

    B. T. - "You are given a string S and a number K as input, and your task is to print S to console output considering that, at most, you can print K characters per line. Example: S = "abracadabra sample" K = 11 Output: abracadabra sample Note that this problem requires the interviewee gather extra requirements from the interviewer (e.g. do we care about multiple white spaces? what if the length of a word is greater than K, ...)"See full answer

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

  • Amazon logoAsked at Amazon 

    "Was the statement very similar to the leetcode or was it changed and only the main idea remained?"

    Anonymous Wombat - "Was the statement very similar to the leetcode or was it changed and only the main idea remained?"See full answer

    Software Engineer
    Coding
    +1 more
  • Adobe logoAsked at Adobe 
    Video answer for 'Given the root of a binary tree of integers, return the maximum path sum.'

    "\# Definition for a binary tree node. class TreeNode: def init(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right class Solution: def maxPathSum(self, root: TreeNode) -> int: self.max_sum = float('-inf')"

    Jerry O. - "\# Definition for a binary tree node. class TreeNode: def init(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right class Solution: def maxPathSum(self, root: TreeNode) -> int: self.max_sum = float('-inf')"See full answer

    Software Engineer
    Coding
    +4 more
  • Amazon logoAsked at Amazon 

    "Count items between indices within compartments compartments are delineated by by: '|' items are identified by: '*' input_inventory = "*||||" inputstartidxs = [1, 4, 6] inputendidxs = [9, 5, 8] expected_output = [3, 0, 1] Explanation: "*||||" 0123456789... indices ++ + # within compartments ^ start_idx = 1 ^ end_idx = 9 -- - # within idxs but not within compartments "*||||" 0123456789... indices "

    Anonymous Unicorn - "Count items between indices within compartments compartments are delineated by by: '|' items are identified by: '*' input_inventory = "*||||" inputstartidxs = [1, 4, 6] inputendidxs = [9, 5, 8] expected_output = [3, 0, 1] Explanation: "*||||" 0123456789... indices ++ + # within compartments ^ start_idx = 1 ^ end_idx = 9 -- - # within idxs but not within compartments "*||||" 0123456789... indices "See full answer

    Software Engineer
    Coding
    +1 more
  • +15

    "with max_score as( select test_id, employee_id, max(score) as max_score from test_results as t1 join tests as t2 on t1.test_id=t2.id group by 2,1 ) select id as employee_id, name as employee_name, sum(maxscore) as totalscore from employees as e join max_score as m on e.id=m.employee_id group by 1,2 order by 3 desc, 1 `"

    Victor N. - "with max_score as( select test_id, employee_id, max(score) as max_score from test_results as t1 join tests as t2 on t1.test_id=t2.id group by 2,1 ) select id as employee_id, name as employee_name, sum(maxscore) as totalscore from employees as e join max_score as m on e.id=m.employee_id group by 1,2 order by 3 desc, 1 `"See full answer

    Data Scientist
    Coding
    +1 more
  • +18

    "-- Write your query here select p.id, p.title, p.budget, count(e.id) as num_employees, sum(e.salary) as total_salaries from projects p join employeesprojects ep on p.id = ep.projectid join employees e on ep.employee_id = e.id group by 1 order by 5 desc; `"

    Anonymous Roadrunner - "-- Write your query here select p.id, p.title, p.budget, count(e.id) as num_employees, sum(e.salary) as total_salaries from projects p join employeesprojects ep on p.id = ep.projectid join employees e on ep.employee_id = e.id group by 1 order by 5 desc; `"See full answer

    Data Scientist
    Coding
    +1 more
  • +6

    "def lowestearningemployees(employees: pd.DataFrame) -> pd.DataFrame: selectedcolumns = employees[['id','firstname','last_name','salary' ]] sorteddf = selectedcolumns.sort_values(by='salary', ascending=True) return sorted_df.head(3)"

    Shatabdi P. - "def lowestearningemployees(employees: pd.DataFrame) -> pd.DataFrame: selectedcolumns = employees[['id','firstname','last_name','salary' ]] sorteddf = selectedcolumns.sort_values(by='salary', ascending=True) return sorted_df.head(3)"See full answer

    Coding
    Data Analysis
  • Goldman Sachs logoAsked at Goldman Sachs 
    +8

    "public static Integer[] findLargest(int[] input, int m) { if(input==null || input.length==0) return null; PriorityQueue minHeap=new PriorityQueue(); for(int i:input) { if(minHeap.size()(int)top){ minHeap.poll(); minHeap.add(i); } } } Integer[] res=minHeap.toArray(new Integer[0]); Arrays.sort(res); return res; }"

    Divya R. - "public static Integer[] findLargest(int[] input, int m) { if(input==null || input.length==0) return null; PriorityQueue minHeap=new PriorityQueue(); for(int i:input) { if(minHeap.size()(int)top){ minHeap.poll(); minHeap.add(i); } } } Integer[] res=minHeap.toArray(new Integer[0]); Arrays.sort(res); return res; }"See full answer

    Machine Learning Engineer
    Coding
    +2 more
  • Video answer for 'E-commerce (2 of 5)'
    +10

    "SELECT items.item_category, SUM(orders.orderquantity) AS totalunitsorderedlast7days FROM orders JOIN items ON orders.itemid = items.itemid WHERE orders.order_date BETWEEN DATE('now', '-6 days') AND DATE('now') GROUP BY items.item_category `"

    Salome L. - "SELECT items.item_category, SUM(orders.orderquantity) AS totalunitsorderedlast7days FROM orders JOIN items ON orders.itemid = items.itemid WHERE orders.order_date BETWEEN DATE('now', '-6 days') AND DATE('now') GROUP BY items.item_category `"See full answer

    Data Scientist
    Coding
    +1 more
  • Amazon logoAsked at Amazon 
    Video answer for 'Implement k-means clustering.'
    Machine Learning Engineer
    Coding
    +4 more
  • +16

    "def friend_distance(friends, userA, userB): step = 0 total_neighs = set() llen = len(total_neighs) total_neighs.add(userB) while len(total_neighs)!=llen: s = set() step += 1 llen = len(total_neighs) for el in total_neighs: nes = neighbours(friends, userA, el) if userA in nes: return step for p in nes: s.add(p) for el in s: total_neighs.add(el) return -1 def neighbours(A,n1, n2): out = set() for i in range(len(A[n2])): if An2: out.add(i) return out"

    Batman X. - "def friend_distance(friends, userA, userB): step = 0 total_neighs = set() llen = len(total_neighs) total_neighs.add(userB) while len(total_neighs)!=llen: s = set() step += 1 llen = len(total_neighs) for el in total_neighs: nes = neighbours(friends, userA, el) if userA in nes: return step for p in nes: s.add(p) for el in s: total_neighs.add(el) return -1 def neighbours(A,n1, n2): out = set() for i in range(len(A[n2])): if An2: out.add(i) return out"See full answer

    Coding
    Data Structures & Algorithms
  • Adobe logoAsked at Adobe 
    Video answer for 'Product of Array Except Self'
    +38

    "Javascript solve: function productExceptSelf(nums) { // your code goes here if(nums.length < 1) return nums; let totalMaxProduct = 1; for(let i=0; i<nums.length; i++) { if(nums[i]!==0) totalMaxProduct*=nums[i]; } for(let i=0; i<nums.length; i++){ if(nums[i]!==0){ nums[i] = totalMaxProduct/nums[i]; } } return nums; } `"

    Aman G. - "Javascript solve: function productExceptSelf(nums) { // your code goes here if(nums.length < 1) return nums; let totalMaxProduct = 1; for(let i=0; i<nums.length; i++) { if(nums[i]!==0) totalMaxProduct*=nums[i]; } for(let i=0; i<nums.length; i++){ if(nums[i]!==0){ nums[i] = totalMaxProduct/nums[i]; } } return nums; } `"See full answer

    Software Engineer
    Coding
    +3 more
  • +10

    "WITH discount AS ( SELECT name, type, CASE WHEN type = 'Electronic' THEN price * 0.90 WHEN type = 'Clothing' THEN price * 0.80 WHEN type = 'Grocery' THEN price * 0.95 WHEN type = 'Book' THEN price * 0.85 ELSE price END AS discounted_price FROM products ) SELECT name, type, ROUND(discountedprice, 2) AS discountedprice FROM discount; `"

    Salome L. - "WITH discount AS ( SELECT name, type, CASE WHEN type = 'Electronic' THEN price * 0.90 WHEN type = 'Clothing' THEN price * 0.80 WHEN type = 'Grocery' THEN price * 0.95 WHEN type = 'Book' THEN price * 0.85 ELSE price END AS discounted_price FROM products ) SELECT name, type, ROUND(discountedprice, 2) AS discountedprice FROM discount; `"See full answer

    Data Scientist
    Coding
    +1 more
  • Coding
    Machine Learning
Showing 81-100 of 344