/Data-Structure-and-Algorithms

Google, Facebook, Amazon, Microsoft, Netflix tech interview questions

Primary LanguageJavaMIT LicenseMIT

Algorithm and Data Structures Interview Questions

HackerRank Logo | Quan Le Profile

HackerRank | Practice, Tutorials & Interview Preparation Solutions

This repository consists of solutions to HackerRank and LeetCode in Problem Solving, Data Structures and Algorithms, and Interview Preparation Kit problems with Python, Java, and SQL.

GitHub last commit GitHub repo size

HackerRank Badges

HackerRank Certificates

Python

Code: Green

  1. Missing Number: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n find the one that is missing from the array.
  2. Single Number: Given a non-empty array of integers, every element appears twice except for one. Find that single one.
  3. Longest Common Prefix: Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "".
  4. Counting Elements: Given an integer array arr, count how many elements x there are, such that x + 1 is also in arr. If there are duplicates in arr, count them seperately.
  5. Add Digits: Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.
  6. High Five: Given a list of scores of different students, return the average score of each student's top five scores in the order of each student's id. Each entry items[i] has items[i][0] the student's id, and items[i][1] the student's score. The average score is calculated using integer division.
  7. Buy and Sell Stock I: Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit. Note that you cannot sell a stock before you buy one.
  8. Buy and Sell Stock II: Say you have an array prices for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times). Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).
  9. Prefix Sum: Given an array of integers nums, write a method that returns the "pivot" index of this array. We define the pivot index as the index where the sum of all the numbers to the left of the index is equal to the sum of all the numbers to the right of the index. If no such index exists, we should return -1. If there are multiple pivot indexes, you should return the left-most pivot index.

Java

Code: Green

  1. Missing Number: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n find the one that is missing from the array.
  2. Single Number: Given a non-empty array of integers, every element appears twice except for one. Find that single one.
  3. Longest Common Prefix: Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "".
  4. Add Digits: Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.
  5. High Five: Given a list of scores of different students, return the average score of each student's top five scores in the order of each student's id. Each entry items[i] has items[i][0] the student's id, and items[i][1] the student's score. The average score is calculated using integer division.
  6. Buy and Sell Stock I: Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit. Note that you cannot sell a stock before you buy one.
  7. Buy and Sell Stock II: Say you have an array prices for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times). Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).
  8. Prefix Sum: Given an array of integers nums, write a method that returns the "pivot" index of this array. We define the pivot index as the index where the sum of all the numbers to the left of the index is equal to the sum of all the numbers to the right of the index. If no such index exists, we should return -1. If there are multiple pivot indexes, you should return the left-most pivot index.

⭐️ From Quan with 💖