├── Behavioral-Questions.md ├── Internship-Roles.md ├── Interview-Resources.md ├── README.md ├── leetcode ├── add_digits.py ├── buy_sell_stock.py ├── climbing_stairs.py ├── contains_duplicate.py ├── find_the_difference.py ├── first_unique_char.py ├── longest_common_prefix.py ├── longest_palindrome.py ├── longest_palindromic_substring.py ├── majority_element.py ├── maximum_product_subarray.py ├── maximum_subarray.py ├── merge_sorted_array.py ├── merge_sorted_linked_lists.py ├── missing_number.py ├── plus_one.py ├── remove_duplicates_linked_list.py ├── reverse_integer.py ├── reverse_vowels_string.py ├── rotate_array.py ├── search_insert_position.py ├── single_number.py ├── string_compression.py ├── two_sum.py ├── valid_palidrome.py └── valid_parenthesis.py └── sql ├── sql_exercises1.sql ├── sql_exercises2.sql ├── sql_exercises3.sql ├── sql_exercises4.sql └── sql_exercises5.sql /Behavioral-Questions.md: -------------------------------------------------------------------------------- 1 | # Self Practice: Behavioral Questions 2 | List of typical behavioral interview questions. Taken from [Udacity Data Science Interview Preparation](https://classroom.udacity.com/courses/ud944). 3 | 4 | ### 1. Getting to Know You 5 | * What motivates you at work? 6 | * Describe what your preferred supervisor—employee relationship looks like. 7 | * What two or three things are most important to you in your work? 8 | 9 | ### 2. Knowledge & Interests 10 | * What do you think are the most pressing issues in this field? 11 | * What challenges does this position present for you? 12 | * What do you think it takes to be successful in this organization? 13 | * What do you know about our company? 14 | 15 | ### 3. Readiness & Experience 16 | * What is your greatest strength/weakness? 17 | * Tell me about a problem you have encountered and how you dealt with it? 18 | * Tell me about a mistake you made and what you learned from it. 19 | * What experience do you have in this field? How have you prepared yourself to switch fields? 20 | 21 | ### 4. Goals, Motivation & Values 22 | * Why do you think you will like this field? 23 | * Describe a time when you saw some problem and took the initiative to correct it rather than waiting for someone else to do it. 24 | * Give me an example of a time you were able to be creative with your work. What was exciting or difficult about it? 25 | * Tell me about a time you were dissatisfied in your work. What could have been done to make it better? 26 | 27 | ### 5. Teamwork 28 | * Describe a time when you worked closely with someone who had a very different personality than you. 29 | * Tell me about a time you faced a conflict while working on a team. How did you handle the conflict? 30 | * Describe a time when you struggled to build a relationship with someone important. 31 | * Tell me about a time you needed to get information from someone who wasn’t very responsive. What did you do? 32 | 33 | ### 6. Ability to Adapt 34 | * Tell me about a time you were under a lot of pressure. What was the situation and how did you get through it? 35 | * Describe a time when your team or company was undergoing change. How did it impact you, and how did you adapt? 36 | * Tell me about your very first job. What did you do to learn the ropes? 37 | * Tell me about a time you failed. How did you deal with this situation? 38 | 39 | ### 7. Time Management Skills 40 | * Tell me about a long-term project that you managed. How did you keep organized and make sure everything was moving along as planned? 41 | * Tell me about a time you set a goal for yourself. How did you ensure that you would meet your objective? 42 | * Give me an example of a time you managed multiple responsibilities. How did you handle it? 43 | 44 | ### 8. Communication Skills 45 | * Tell me about a time you successfully persuaded someone to understand your perspective at work. 46 | * Describe a time when you were the primary “expert”. How did you ensure that everyone understood you? 47 | * Describe a time when you could only use written communication to get your ideas across to your team. 48 | -------------------------------------------------------------------------------- /Internship-Roles.md: -------------------------------------------------------------------------------- 1 | # Data Science and Software Engineer Intern Roles 2 | Compilation of 200+ undergraduate data science and software engineering intern positions offered for Summer 2018 3 | 4 | ### Introduction 5 | This list is a compilation of intern roles from Summer 2018 that were explicitly centered around data science and software engineering. It's recommended that you bookmark this so that you can come back to it as a reference when job hunting later on. While fairly comprehensive, you'll notice that my search was bias toward major cities, particularly on the west coast. I recommend that you focus on the companies themselves more so than their accompanying locations listed below, since locations often vary from year-to-year. 6 | 7 | Lastly, this list is in no particular order and just because a company offered the position for last summer is no guarantee that they will next summer! However, it is a good starting point for your search. My mission is to expand on a similar list that I used with more recent, specified listings. This list has an accompanying Medium post as well if you're interested. Enjoy! 8 | 9 | ### See the Post 10 | I wrote a Medium post on the experience as well filtered for only Data Science Intern positions specifically. You can find the post and more about the process here: 11 | 12 | [Big List of 50+ Data Science Internships](https://towardsdatascience.com/big-list-of-50-data-science-internships-ee917ed3413f) 13 | 14 | ### Data 15 | * Anki San Francisco, CA AI Intern 16 | * Ebay San Jose, CA AI/ML/Data Science Undergrad Intern 17 | * Thumbtack San Francisco, CA Analytics Intern 18 | * Ticketmaster Chicago, IL Analytics Intern 19 | * Attention Global New York, NY Analytics Intern 20 | * Unity Technologies San Francisco, CA Analytics/Data Science Intern 21 | * Snap Inc. Santa Monica, CA BI & Reporting Intern 22 | * SAP Palo Alto, CA Big Data Developer Intern 23 | * Avvo Seattle, WA Big Data Engineer Intern 24 | * Palo Alto Networks Santa Clara, CA Big Data Intern 25 | * Teradata Seattle, WA Big Data Intern 26 | * Roblox San Mateo, CA Big Data Intern 27 | * Descartes Labs Santa Fe, NM Computer Vision Intern 28 | * Patagonia Reno, NV Customer Insights & Innovation Intern 29 | * Gizmodo New York, NY Data & Analytics Intern 30 | * Ubisoft San Francisco, CA Data Analyst Intern 31 | * RetailNext San Jose, CA Data Analyst Intern 32 | * Snap! Raise Seattle, WA Data Analyst Intern 33 | * Cogo Labs Cambridge, MA Data Analyst Intern 34 | * CareDash Cambridge, MA Data Analyst Intern 35 | * Logickull San Francisco, CA Data Analyst Intern 36 | * Horizon Media New York, NY Data Analyst Intern 37 | * NetEase Brisbane, CA Data Analyst Intern 38 | * Juniper Networks Sunnyvale, CA Data Analyst Intern 39 | * Saavan New York, NY Data Analyst Intern 40 | * Definitive Healthcare Framington, MA Data Analyst Intern 41 | * JUUL Labs New York, NY Data Analyst Intern 42 | * FireEye Amsterdam, NL Data Analyst Intern 43 | * Capital One McLean, VA Data Analyst/Science Intern 44 | * Red Hat Westford, MA Data Analytics Engineering Intern 45 | * London Theatre Direct Prague, Czech Republic Data Analytics Intern 46 | * AT&T Unknown, CA Data Analytics Intern 47 | * Mindshare New York, NY Data and Analytics Intern 48 | * Comcast Philadelphia, PA Data and Business Analytics Intern 49 | * Outbrain New York, NY Data Center Engineering Intern 50 | * Tesla Palo Alto, CA Data Engineer Intern 51 | * Factual Inc Los Angeles, CA Data Engineer Intern 52 | * Flatiron Health New York, NY Data Engineer Intern 53 | * New York Times New York, NY Data Engineer Intern 54 | * Avanade New York, NY Data Engineer Intern 55 | * Weebly San Francisco, CA Data Engineering Intern 56 | * Illumina Santa Clara, CA Data Infastructure and Analyst Intern 57 | * Wayfair Boston, MA Data Operations Analyst Intern 58 | * Stitch Fix San Francisco, CA Data Platform Intern 59 | * Nvidia CA, WA, TX Data Platform Intern 60 | * 87AM Los Angeles, CA Data Research Intern 61 | * Workday Pleasanton, CA Data Science Intern 62 | * Airbnb San Francisco, CA Data Science Intern 63 | * Quora Mountain View, CA Data Science Intern 64 | * IBM Multiple Locations Data Science Intern 65 | * VMware Palo Alto, CA Data Science Intern 66 | * Taboola Los Angeles, CA Data Science Intern 67 | * Chegg Santa Clara, CA Data Science Intern 68 | * CrowdStrike El Segundo, CA Data Science Intern 69 | * Airware San Francisco, CA Data Science Intern 70 | * Chef'd El Segundo, CA Data Science Intern 71 | * Allstate Menlo Park, CA Data Science Intern 72 | * HG Data Santa Barbara, CA Data Science Intern 73 | * Walmart San Bruno, CA Data Science Intern 74 | * ViaSat San Diego, CA Data Science Intern 75 | * 1010data New York, NY Data Science Intern 76 | * ZestFinance Los Angeles, CA Data Science Intern 77 | * Kayak Cambridge, MA Data Science Intern 78 | * Upstart San Carlos, CA Data Science Intern 79 | * BXB Digital San Francisco, CA Data Science Intern 80 | * Uptake Chicago, IL Data Science Intern 81 | * Tala Santa Monica, CA Data Science Intern 82 | * Infoblox Tacoma, WA Data Science Intern 83 | * Tivo Boston, MA Data Science Intern 84 | * Brandless Inc San Francisco, CA Data Science Intern 85 | * Wealthfront Redwood City, CA Data Science Intern 86 | * Rule14 Santa Monica, CA Data Science Intern 87 | * Jump Capital Chicago, IL Data Science Intern 88 | * Nielsen Tampa, FL Data Science Intern 89 | * Zylab Amersterdam, NL Data Science Intern 90 | * Centerfield Corporation Los Angeles, CA Data Science Intern 91 | * Leaf Group Santa Monica, CA Data Science Intern 92 | * Solar Turbines San Diego, CA Data Science Intern 93 | * Swiss Re New York, NY Data Science Intern 94 | * C3 IoT Redwood City, CA Data Science Intern 95 | * Remedy Partners New York, NY Data Science Intern 96 | * Hudl London, France Data Science Intern 97 | * Acorns Anaheim, CA Data Science Intern 98 | * Foot Locker New York, NY Data Science Intern 99 | * College Board Reston, VA Data Science Intern 100 | * Proctor & Gamble Geneva, Switzerland Data Science Intern 101 | * Automated Insights Duram, NC Data Science Intern 102 | * HomeAway Austin, TX Data Science Intern 103 | * Optimus Consulting Washington, DC Data Science Intern 104 | * Shumway Capital New York, NY Data Science Intern 105 | * Expedia Bellevue, WA Data Science Intern 106 | * iRobot Bedford, MA Data Science Intern 107 | * Pluvio New York, NY Data Science Intern 108 | * GumGum Santa Monica, CA Data Science Intern (NLP) 109 | * Uptown Treehouse San Francisco, CA Data Science Marketing Intern 110 | * Cambia Portland, OR Data Science Product Mgt Intern 111 | * Two Six Labs Arlington, VA Data Science Research Intern 112 | * LinkedIn Sunnyvale, CA Data Science, Analytics Intern 113 | * Clearlink Salt Lake City, UT Data Science/Developement Intern 114 | * NetApp Sunnyvale, CA Data Science/Machine Learning Intern 115 | * Pure Storage Mountain View, CA Data Science/Mining Intern 116 | * Raytheon State College, PA Data Science/Software Eng. Intern 117 | * Boeing Seattle, WA Data Sciences Intern 118 | * Accolade Seattle, WA Data Scientist Engineer Intern 119 | * Cisco San Jose, CA Data Scientist Intern 120 | * Mckinsey & Company New York, NY/Boston, MA Data Scientist Intern 121 | * Awair San Francisco, CA Data Scientist Intern 122 | * ExtraHop Seattle, WA Data Scientist Intern 123 | * American Century Investments Mountain View, CA Data Scientist Intern 124 | * Booz Allen Hamilton San Antonio, TX Data Scientist Intern 125 | * Spotify New York, NY Data Scientist: Ads & Markets Analytics Intern 126 | * USAA San Antonio, TX Decision Science Analyst Intern 127 | * Volkswagon Belmont, CA Deep Learning Intern 128 | * GE Digital San Ramon, CA Digital Technology Intern 129 | * MetaRail, Inc San Francisco, CA Ecommerce Operations & Analytics Intern 130 | * PlayStation San Diego, CA Gamer Insight Data Analyst Intern 131 | * Payscout Los Angeles, CA Information Technology Intern 132 | * Connexity Inc Los Angeles, CA Intern (Big Data/Marketing) 133 | * Factset New York, NY Machine Learning Engineer Intern 134 | * OpenAI San Francisco, CA Machine Learning Fellow 135 | * Mercedes Sunnyvale, CA Machine Learning Intern 136 | * The Aerospace Corporation El Segundo, CA Machine Learning Intern 137 | * EA Redwood City, CA Machine Learning Intern 138 | * Unifi Software San Mateo, CA Machine Learning Intern 139 | * HighCrown New York, NY Machine Learning Intern 140 | * Wiley Job Network Boston, MA MRL Data Scientist Intern 141 | * FreshDirect New York, NY Operations Analyst Intern 142 | * Pandora Oakland, CA Product Analytics Intern 143 | * Github San Francisco, CA Quantitative Researcher Intern 144 | * Two Sigma New York, NY Quantitative Researcher Intern 145 | * Equinix Sunnyvale, CA Reporting & Analytics Intern 146 | * FleishmanHillard New York, NY Research & Analytics Intern 147 | * Squarespace New York, NY Software Engineer - ML Intern 148 | * Accenture San Francisco, CA Software Engineer Analyst Intern 149 | * AppDynamics San Francisco, CA Software Engineer Intern - Analytics 150 | * TripAdvisor Needham, MA Software Engineer Intern/ML Intern 151 | * Splunk San Francisco, CA Software Engineer/Data Analyst Intern 152 | * Yelp San Francisco, CA Software/Data Mining Engineer Intern 153 | * Amazon Robotics North Reading, MA Soluions Analytics Intern 154 | * PMK BNC Los Angeles, CA Strategic Inisights & Analytics 155 | * BuzzFeed Los Angeles, CA Strategic Insights & Analytics 156 | * Twitter San Francisco, CA University Data Intern 157 | 158 | 159 | ### Development 160 | * Udacity Mountain View, CA Content Developer Intern SDC 161 | * Moody's Analytics San Francisco, CA Engineering & Technology Intern 162 | * Foursquare New York, NY Engineering Intern 163 | * BloomReach Mountain View, CA Engineering Intern 164 | * Asana San Francisco, CA Engineering Intern 165 | * ROOM8 San Francisco, CA Engineering Intern 166 | * Optimizely San Francisco, CA Engineering Summer Intern 167 | * Houzz Palo Alto, CA Engineering Summer Intern 168 | * Under Armour Baltimore, MD Rookie Summer Intern 2018 169 | * Khan Academy Mountain View, CA Software Developer Intern 170 | * Amazon Seattle, WA Software Development Intern 171 | * Atlassian San Francisco, CA Software Development Intern 172 | * Zillow Seattle, WA Software Development Intern 173 | * Hulu Santa Monica, CA Software Development Intern 174 | * Siemens Cypress, CA Software Development Intern 175 | * 24[7] San Jose, CA Software Development Intern 176 | * Apple Cupertino, CA Maps Software Engineering Intern 177 | * A9 Palo Alto, CA ML Software Development Intern 178 | * Lyft San Francisco, CA Software Engineer Intern 179 | * Dropbox San Francisco, CA Software Engineer Intern 180 | * Intel Santa Clara, CA Software Engineer Intern 181 | * Facebook CA, WA Software Engineer Intern 182 | * Uber San Francisco, CA Software Engineer Intern 183 | * Square Atlanta, GA Software Engineer Intern 184 | * Groupon San Francisco, CA Software Engineer Intern 185 | * Etsy New York, NY Software Engineer Intern 186 | * Microsoft Redmond, WA Software Engineer Intern 187 | * Google San Francisco, CA Software Engineer Intern 188 | * Pinterest San Francisco, CA Software Engineer Intern 189 | * Youtube San Francisco, CA Software Engineer Intern 190 | * Slack San Francisco, CA Software Engineer Intern 191 | * Fitbit Boston, MA Software Engineer Intern 192 | * Stripe San Francisco, CA Software Engineer Intern 193 | * Salesforce San Francisco, CA Software Engineer Intern 194 | * Wish San Francisco, CA Software Engineer Intern 195 | * Nest Palo Alto, CA Software Engineer Intern 196 | * Addepar Mountain View, CA Software Engineer Intern 197 | * Twilio San Francisco, CA Software Engineer Intern 198 | * PayPal Boston, MA Software Engineer Intern 199 | * Blend San Francisco, CA Software Engineer Intern 200 | * Palantir New York, NY Software Engineer Intern 201 | * Nextdoor San Francisco, CA Software Engineer Intern 202 | * LendUp San Francisco, CA Software Engineer Intern 203 | * LiveRamp San Francisco, CA Software Engineer Intern 204 | * Medallia San Mateo, CA Software Engineer Intern 205 | * Snowflake Computing San Mateo, CA Software Engineer Intern 206 | * Tableau Seattle, WA Software Engineer Intern 207 | * Zynga San Francisco, CA Software Engineer Intern 208 | * Beme New York, NY Software Engineer Intern 209 | * Quantcast San Francisco, CA Software Engineer Intern 210 | * HP San Diego, CA Software Engineer Intern 211 | * Rubrik Inc. Palo Alto, CA Software Engineer Intern 212 | * Quid San Francisco, CA Software Engineer Intern 213 | * Petal New York, NY Software Engineer Intern 214 | * MemSQL San Francisco, CA Software Engineer Intern 215 | * Bloomberg New York, NY Software Engineer Intern 216 | * Qualcomm San Diego, CA Software Engineer Intern 217 | * Dell Santa Clara, CA Software Engineer Intern 218 | * Redfin San Francisco, CA Software Engineer Intern 219 | * AB New York, NY Software Engineer Intern 220 | * MongoDB New York, NY Software Engineer Intern 221 | * Visa San Francisco, CA Software Engineer Intern 222 | * Datto Boston, MA Software Engineer Intern 223 | * Zynga Carlsbad, CA Software Engineer Intern 224 | * Datadog New York, NY Software Engineer Intern 225 | * Cohesity Santa Clara, CA Software Engineer Intern 226 | * Lenovo Santa Clara, CA Software Engineer Intern 227 | * Box Redwood City, CA Software Engineer Intern 228 | * Qualtrics Seattle, WA Software Engineer Intern 229 | * Redbubble San Francisco, CA Software Engineer Intern 230 | * Duolingo Pittsburgh, PA Software Engineer Intern 231 | * Pocket Gems San Francisco, CA Software Engineer Intern 232 | * Oath San Francisco, CA Software Engineer Intern 233 | * MailChimp Atlanta, GA Software Engineer Intern 234 | * MuleSoft San Francisco, CA Software Engineer Intern 235 | * Yext New York, NY Software Engineer Intern 236 | * Braintree Chicago, IL Software Engineer Intern 237 | * Akamai Cambridge, MA Software Engineer Intern 238 | * Palantir Palo Alto, CA Software Engineer Intern 239 | * Classy San Diego, CA Software Engineer Intern 240 | * Zocdoc New York, NY Software Engineering Intern 241 | * Jet Hoboken, NJ Software Engineering Intern 242 | * Informatica Redwood City, CA Software Engineering Intern 243 | * Qubol Santa Clara, CA Software Engineering Intern 244 | * STMicroelectronics San Francisco, CA Student Intern 245 | * OpenTable San Francisco, CA Summer Engineering Intern 246 | * Couple San Francisco, CA Summer Intern 247 | * SpaceX Irvine, CA Summer Intern 248 | * Phosphorus New York, NY Summer Research Intern 249 | * Northup Grumman Sunnyvale, CA Technical Engineering Intern 250 | * Proofpoint Sunnyvale, CA Technical Intern 251 | * Nike Beaverton, OR Technology Undergrad Intern 252 | -------------------------------------------------------------------------------- /Interview-Resources.md: -------------------------------------------------------------------------------- 1 | # Data Science Interview Resources 2 | 50+ interviews worth of comprehensive data science resources 3 | 4 | ### Introduction 5 | Data science interviews certainly aren’t easy. I know this first hand. I’ve participated in over 50 individual interviews and phone screens while applying for competitive internships over the last calendar year. Through this exciting and somewhat (at times, very) painful process, I’ve accumulated a plethora of useful resources that helped me prepare for and eventually pass data science interviews. Long story short, I’ve decided to sort through all my bookmarks and notes in order to deliver a comprehensive list of data science resources. With this list by your side, you should have more than enough effective tools at your disposal next time you’re prepping for a big interview. 6 | 7 | ### See the Post 8 | I wrote a Medium post on the experience as well. You can find the post and more about my experience here: 9 | 10 | [The Big List of DS/ML Interview Resources](https://towardsdatascience.com/the-big-list-of-ds-ml-interview-resources-2db4f651bd63?source=friends_link&sk=e229d4fc3452514bd8d560ae898809cc) 11 | 12 | ### General 13 | * Interview Q&A bank 14 | * https://github.com/iamtodor/data-science-interview-questions-and-answers 15 | * Tech Interview Handbook 16 | * https://github.com/yangshun/tech-interview-handbook 17 | * Best Data Science Courses Online 18 | * https://medium.freecodecamp.org/the-best-data-science-courses-on-the-internet-ranked-by-your-reviews-6dc5b910ea40 19 | * What it’s like to be on the data science job market 20 | * http://treycausey.com/data_science_interviews.html 21 | * Learn Data Science on Quora 22 | * https://datascienceinterview.quora.com/ 23 | * Tips for Data Science Interviews on Quora 24 | * https://www.quora.com/What-are-tips-for-data-science-interviews-1 25 | * How do I prepare for a phone interview with Airbnb? 26 | * https://www.quora.com/How-do-I-prepare-for-a-phone-interview-for-a-data-scientist-position-with-Airbnb 27 | * Emily Robinson Advice Applying to Data Science Jobs 28 | * http://hookedondata.org/Advice-for-Applying-to-Data-Science-Jobs/ 29 | * Two Sides of Getting a Job as a Data Scientist 30 | * https://towardsdatascience.com/the-two-sides-of-getting-a-job-as-a-data-scientist-a4571acc58bc 31 | * Robert Chang Doing Data Science at Twitter 32 | * https://medium.com/@rchang/my-two-year-journey-as-a-data-scientist-at-twitter-f0c13298aee6 33 | * Questions I’m Asking in Interviews 34 | * https://jvns.ca/blog/2013/12/30/questions-im-asking-in-interviews/ 35 | * Creating a Great Data Science Resume 36 | * https://will-stanton.com/2015/07/15/creating-a-great-data-science-resume/ 37 | * Data Science Interview Guide 38 | * https://towardsdatascience.com/data-science-interview-guide-4ee9f5dc778 39 | * 3 Types of Data Science Interview Questions Joma Tech 40 | * https://www.youtube.com/watch?v=4Z6lxfglvUU 41 | * How to Land a Data Scientist Position at Airbnb 42 | * https://towardsdatascience.com/how-to-land-a-data-scientist-job-at-your-dream-company-my-journey-to-airbnb-f6a1e99892e8 43 | * Red Flags In Data Science Interviews 44 | * http://hookedondata.org/Red-Flags-in-Data-Science-Interviews/ 45 | * Advice Building out a Portfolio 46 | * https://medium.com/@jasonkgoodman/advice-on-building-data-portfolio-projects-c5f96d8a0627 47 | * Youtube William Chen Resume/Portfolio Tips 48 | * https://www.youtube.com/watch?v=xrhPjE7wHas&feature=youtu.be&t=2m43s 49 | * How to Prepare for Data Science Interviews Quora Answers 50 | * https://www.quora.com/How-do-I-prepare-for-a-data-scientist-interview 51 | * 120 Data Science Questions Answers 52 | * https://github.com/kojino/120-Data-Science-Interview-Questions 53 | * Analytics Vidhya Comprehensive Interview Resources 54 | * https://www.analyticsvidhya.com/blog/2018/06/comprehensive-data-science-machine-learning-interview-guide/ 55 | * Dataquest Data Science Career Guide 56 | * https://www.dataquest.io/blog/data-science-career-guide/?utm_campaign=Data_Elixir&utm_medium=email&utm_source=Data_Elixir_227 57 | * Notes and technical questions from interviewing as a Data Scientist in 2018 58 | * https://towardsdatascience.com/notes-and-technical-questions-from-interviewing-as-a-data-scientist-in-2018-20e7e3ee4ab3 59 | * Mastering the Data Science Interview Loop 60 | * https://towardsdatascience.com/mastering-the-data-science-interview-15f9c0a558a7 61 | 62 | 63 | ### Algorithmic Coding & Python 64 | * Time complexity in Python 65 | * https://wiki.python.org/moin/TimeComplexity 66 | * Leetcode 67 | * https://leetcode.com/ 68 | * Stacks and queues in Python 69 | * https://gist.github.com/RatulSaha/b41c52614da34762a74d16dc066b68df#file-list-py 70 | * Preparing for Programming Interviews with Python 71 | * https://medium.com/@ratulsaha/preparing-for-programming-interview-as-a-phd-student-with-python-5f8af8b40d5f 72 | * Coding Interview University on Github 73 | * https://github.com/jwasham/coding-interview-university#about-video-resources 74 | * Philip Guo Programming Interview Tips 75 | * http://www.pgbovine.net/programming-interview-tips.htm 76 | * Google Python Style Guide 77 | * https://github.com/google/styleguide/blob/gh-pages/pyguide.md 78 | * Algorithms in Python Github 79 | * https://github.com/TheAlgorithms/Python 80 | * Intro to Classes and Objects in Python 81 | * https://www.youtube.com/watch?v=wfcWRAxRVBA 82 | * Coding Interview Github Compilation 83 | * https://github.com/mre/the-coding-interview 84 | * Problem Solving with Data Structures & Algorithms in Python 85 | * http://interactivepython.org/runestone/static/pythonds/index.html 86 | * Python Leetcode Video Series Nasr Maswood 87 | * https://www.youtube.com/watch?v=Xorvwc2P0-8&list=PL6AvMp7YYQRxyltgP9mucWXYxcn1e2mx3 88 | * Python Tricks and Tips 89 | * https://hackernoon.com/python-tricks-101-2836251922e0 90 | * Big List of Interviewee Interview Questions 91 | * https://github.com/yangshun/tech-interview-handbook/blob/master/non-technical/questions-to-ask.md 92 | 93 | 94 | ### Statistics and Probability 95 | * Basics of Probability for Data Science 96 | * https://www.analyticsvidhya.com/blog/2017/02/basic-probability-data-science-with-examples/ 97 | * William Chen Probability Cheatsheet 98 | * https://static1.squarespace.com/static/54bf3241e4b0f0d81bf7ff36/t/55e9494fe4b011aed10e48e5/1441352015658/probability_cheatsheet.pdf 99 | * 40 Questions on Probability for Data Science Interviews 100 | * https://www.analyticsvidhya.com/blog/2017/04/40-questions-on-probability-for-all-aspiring-data-scientists/ 101 | * Common Probability Distributions 102 | * http://blog.cloudera.com/blog/2015/12/common-probability-distributions-the-data-scientists-crib-sheet/ 103 | * Probability and Statistics for DS Medium Series 104 | * https://towardsdatascience.com/probability-statistics-for-data-science-series-83b94353ca48 105 | 106 | 107 | ### Data Manipulation & SQL 108 | * Mode Tutorial 109 | * https://community.modeanalytics.com/sql/tutorial/introduction-to-sql/ 110 | * How to Ace Data Science Interviews: SQL 111 | * https://towardsdatascience.com/how-to-ace-data-science-interviews-sql-b71de212e433 112 | * How to Write Better Queries (Datacamp) 113 | * https://www.datacamp.com/community/tutorials/sql-tutorial-query 114 | * Practice SQL problems 115 | * https://github.com/MaximAbramchuck/awesome-interview-questions#sql 116 | * 10 Frequently Asked SQL Questions 117 | * http://www.java67.com/2013/04/10-frequently-asked-sql-query-interview-questions-answers-database.html 118 | * 45 Essential SQL Interview Questions 119 | * https://www.toptal.com/sql/interview-questions 120 | * More SQL practice on Github 121 | * https://github.com/XD-DENG/SQL-exercise 122 | 123 | 124 | ### Data Analysis & Pandas 125 | * Data School Video Series 126 | * https://www.youtube.com/playlist?list=PL5-da3qGB5ICCsgW1MxlZ0Hq8LL5U3u9y 127 | * Intro to Pandas Data Strutures 128 | * http://www.gregreda.com/2013/10/26/intro-to-pandas-data-structures/ 129 | * Excel Tasks in Pandas 130 | * http://pbpython.com/excel-pandas-comp.html 131 | * Data Analyst Interview Practice Checkist Udacity 132 | * https://classroom.udacity.com/courses/ud944/lessons/d982ccec-8895-4362-981e-05bd266ac783/concepts/399b5b79-7fa9-435d-91ed-bd74369ff5d9 133 | * More Pandas Exercises on Github 134 | * https://github.com/guipsamora/pandas_exercises 135 | 136 | 137 | ### Machine Learning 138 | * Machine Learning in Python Github Repo 139 | * https://github.com/machinelearningmindset/machine-learning-course 140 | * The Applied Machine Learning Process 141 | * https://machinelearningmastery.com/process-for-working-through-machine-learning-problems/ 142 | * Springboard 41 Essential Machine Learning Questions 143 | * https://www.springboard.com/blog/machine-learning-interview-questions/ 144 | * Data School 15 Hours of Machine Learning Videos 145 | * https://www.dataschool.io/15-hours-of-expert-machine-learning-videos/ 146 | * Difference between boosting and bagging 147 | * https://quantdare.com/what-is-the-difference-between-bagging-and-boosting/ 148 | * Comprehensive Guide to Ensemble Learning Analytics Vidhya 149 | * https://www.analyticsvidhya.com/blog/2018/06/comprehensive-guide-for-ensemble-models/ 150 | * Kaggle Data Science Glossary 151 | * https://www.kaggle.com/shivamb/data-science-glossary-on-kaggle 152 | * Machine Learning Interview Checklist Udacity 153 | * https://docs.google.com/document/d/e/2PACX-1vSYBV2l-IUU8rFPa6ldB5CSCrrnz_czoVMGN5G2hRRjfUjlG82a-tif0sO4QUF_MBkgeOj6U44ACOqM/pub?embedded=true 154 | * Google Machine Learning Glossary 155 | * https://developers.google.com/machine-learning/glossary/ 156 | * 100 Days of ML Code Infographics 157 | * https://github.com/Avik-Jain/100-Days-Of-ML-Code 158 | * Machine Learning for Dummies Algorithm Overview 159 | * https://www.dummies.com/programming/big-data/data-science/machine-learning-dummies-cheat-sheet/ 160 | * ML Algorithm Pros and Cons 161 | * https://www.hackingnote.com/en/machine-learning/algorithms-pros-and-cons/ 162 | * Advantages of Different Classification Algorithms 163 | * https://www.quora.com/What-are-the-advantages-of-different-classification-algorithms 164 | * The MLInterview Repo 165 | * https://github.com/theainerd/MLInterview 166 | 167 | 168 | ### Product and Experimentation 169 | * Experiments at Airbnb 170 | * https://medium.com/airbnb-engineering/experiments-at-airbnb-e2db3abf39e7 171 | * When Should A/B testing not be trusted? 172 | * https://www.quora.com/When-should-A-B-testing-not-be-trusted-to-make-decisions 173 | * TutorialsPoint A/B testing questions 174 | * https://www.tutorialspoint.com/ab_testing/ab_testing_interview_questions.htm 175 | * Udacity A/B Testing Course 176 | * https://www.udacity.com/course/ab-testing--ud257 177 | * Summery of Udacity A/B Testing Course 178 | * https://towardsdatascience.com/a-summary-of-udacity-a-b-testing-course-9ecc32dedbb1 179 | * Hubspot Frequently Asked Questions about A/B Testing 180 | * https://blog.hubspot.com/blog/tabid/6307/bid/33466/answers-to-the-19-most-frequently-asked-questions-about-a-b-testing.aspx 181 | * Introduction to Churn in Python 182 | * https://www.datascience.com/blog/churn-prediction-python 183 | * How Do You Set Metrics? - Julie Zhou 184 | * https://medium.com/the-year-of-the-looking-glass/how-do-you-set-metrics-59f78fea7e44 185 | * Metrics vs. Experience - Julie Zhou 186 | * https://medium.com/the-year-of-the-looking-glass/metrics-versus-experience-a9347d6b80b 187 | * How Not to Run an A/B Test 188 | * http://www.evanmiller.org/how-not-to-run-an-ab-test.html 189 | * 12 Guidlines for A/B Tests 190 | * http://hookedondata.org/Guidelines-for-AB-Testing/?utm_campaign=Data_Elixir&utm_medium=email&utm_source=Data_Elixir_194 191 | * A/B Testing at Stack Overflow 192 | * https://juliasilge.com/blog/ab-testing/ 193 | * Type I vs. Type II Errors Simplified 194 | * https://flowingdata.com/2014/05/09/type-i-and-ii-errors-simplified/ 195 | * A/B Testing TutorialPoint 196 | * https://www.tutorialspoint.com/ab_testing/index.htm 197 | * Case Study: Pay as You Go 198 | * https://www.forbes.com/sites/quora/2015/05/29/you-can-earn-as-much-or-more-from-a-pay-what-you-want-model-as-from-a-fixed-price-model/#65b3a67221b5 199 | * 27 Metrics Used at Pinterest 200 | * http://jwegan.com/growth-hacking/27-metrics-pinterests-internal-growth-dashboard/ 201 | * 70 Resources to Get Started With A/B Testing 202 | * https://www.quicksprout.com/2014/11/05/ab-testing-for-beginners-70-resources-to-get-you-started/ 203 | 204 | ### Big Data 205 | * Apache Spark in Python: Beginner’s Guide (Datacamp) 206 | * https://www.datacamp.com/community/tutorials/apache-spark-python#gs.fMIIqxM 207 | * Apache Spark vs. Mapreduce Whiteboard Walkthrough 208 | * https://www.youtube.com/watch?v=KzFe4T0PwQ8 209 | * Differences Between Hadoop and Spark 210 | * https://www.quora.com/What-is-the-difference-between-Hadoop-and-Spark 211 | * What is Hadoop?: SQL Comparison 212 | * https://www.youtube.com/watch?v=MfF750YVDxM 213 | * Data Engineering Interactive Map 214 | * http://xyz.insightdataengineering.com/blog/pipeline_map/ 215 | * How to Learn Apache Spark? Quora Post 216 | * https://www.quora.com/How-do-I-learn-Apache-Spark 217 | * Youtube Intro to Big Data with PySpark 218 | * https://www.youtube.com/playlist?list=PLE50-dh6JzC5zo2whIGqJ02CIhP3ysQLX 219 | * Spark Documentation Screencasts 220 | * http://spark.apache.org/screencasts/1-first-steps-with-spark.html 221 | * PySpark Cheatsheet 222 | * https://www.datacamp.com/community/blog/pyspark-cheat-sheet-python 223 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Data Science Career Resources 2 | Compilation of resources and insights that helped me on my journey to data scientist. Reposted for readability: 3 | 4 | [The Big List of Data Science Interview Resources](https://www.conordewey.com/blog/the-big-list-of-data-science-interview-resources/) 5 | 6 | ### Introduction 7 | Data science can seem like an intimidating field to get into. I know this first hand. Throughout my journey, I've learned a lot. I've also documented a lot. Through this process, I’ve accumulated a bunch of useful resources that helped me with learning new concepts, doing impactful work, interviewing at top tech companies, and more. This repo is an attempt to ‘open-source’ my experience and insights becoming a data scientist. Enjoy! 8 | 9 | ### ⭐️ [Data Science Interview Resources](https://www.conordewey.com/blog/the-big-list-of-data-science-interview-resources/) 10 | With this by your side, you should have more than enough material at your disposal the next time you’re prepping for a big interview or suring up fundamental concepts. Being updated and improved on constantly. 11 | 12 | ### [Data Science and Software Engineering Intern Roles](https://github.com/conordewey3/DS-Career-Resources/blob/master/Internship-Roles.md) 13 | This list is a compilation of over 200+ undergraduate intern roles from Summer 2018 that were explicitly centered around data science and software engineering. You can use this as a jumping off point for your next job search. 14 | 15 | ### [Compilation of Advice for New and Aspiring Data Scientists](https://www.conordewey.com/blog/compilation-of-advice-for-new-and-aspiring-data-scientists/) 16 | This post was designed to make it a little easier for aspiring data scientists to find all of the excellent advice out there from experts in the field. The majority of the ideas are condensed from 6 posts that I found especially helpful. 17 | 18 | ### [5 Lessons from a Data Science Intern at a Tech Unicorn](https://www.conordewey.com/blog/5-lessons-from-a-data-science-intern-at-a-tech-unicorn/) 19 | A reflection of lessons and advice from my time at a Data Science Intern working at Unity Technologies in San Francisco, CA. My goal is to share a handful of actionable lessons, takeaways, thoughts, and advice from the memorable experience. 20 | 21 | ### [5 Resources to Inspire Your Next Data Science Project](https://www.conordewey.com/blog/5-resources-to-inspire-your-next-data-science-project/) 22 | Have you ever wanted to start a new project but you can’t decide what to do? First, you spend a couple hours brainstorming ideas. Then days. Before you know it, weeks have gone by without shipping anything new. In this post, my intention is provide some useful resources to springboard you into your next data science project. 23 | 24 | ### [The Hitchhiker's Guide to Machine Learning in Python](https://www.conordewey.com/blog/the-hitchhikers-guide-to-machine-learning-in-python/) 25 | Learn how to implement 8 fundamental machine learning algorithms in Python over the course of 8 minutes or less by leveraging the power of scikit-learn and Python for data science. 26 | 27 | ### [Python for Data Science: 8 Concepts You May Have Forgotten](https://www.conordewey.com/blog/python-for-data-science-8-concepts/) 28 | If you’ve ever found yourself looking up the same question, concept, or syntax over and over again when programming, you’re not alone. Here’s the stuff that I’m always forgetting when working with Python, NumPy, and Pandas. 29 | 30 | ### [13 Essential Newsletters for Data Scientists](https://www.conordewey.com/blog/13-essential-newsletters-for-data-scientists-remastered/) 31 | Think of your newsletter subscriptions as an elite force of smart, specialized people working to bring you the latest and most valuable information well worth your time. Data science moves fast, you should too. 32 | 33 | ### [An Ode to the Type A Data Scientist](https://www.conordewey.com/blog/an-ode-to-the-type-a-data-scientist/) 34 | Data science isn't entirely about machine learning. Here I make the argument for the value provided by skills and actions associated with the often overlooked and under-appreciated, Type A Data Scientist. 35 | 36 | ### [When Your Job Is Done as a Data Scientist](https://www.conordewey.com/blog/when-your-job-is-done-as-a-data-scientist/) 37 | As Data Scientists, there is very little that is black and white. We do our work in a world of grey. We need to do a better job of consistently reminding ourselves that our primary focus should be to drive impact. 38 | 39 | ### [The Edge You Need at Your Next Interview](https://www.conordewey.com/blog/the-edge-you-need-at-your-next-interview/) 40 | This post is designed to help you achieve an edge in data science interviews by laying out a multi-step system to product knowledge and ideation that I’ve used with a lot of success. 41 | -------------------------------------------------------------------------------- /leetcode/add_digits.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 258. Add Digits 4 | 5 | Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. 6 | 7 | Example: 8 | Input: 38 9 | Output: 2 10 | Explanation: The process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it. 11 | 12 | Follow up: 13 | Could you do it without any loop/recursion in O(1) runtime? 14 | 15 | ''' 16 | 17 | # Initial approach - O(n) time, O(n) space 18 | def addDigits(self, num): 19 | digits = [int(x) for x in str(num)] 20 | while sum(digits) > 9: 21 | temp = sum(digits) 22 | digits = [int(x) for x in str(temp)] 23 | return sum(digits) 24 | 25 | 26 | # More concise approach - O(n) time, O(n) space 27 | def addDigits(self, num): 28 | while num > 9: 29 | num = sum(list(map(int, str(num)))) 30 | return num 31 | 32 | -------------------------------------------------------------------------------- /leetcode/buy_sell_stock.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 121. Best Time to Buy and Sell Stock 4 | 5 | Say you have an array for which the ith element is the price of a given stock on day i. 6 | 7 | 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. 8 | 9 | Note that you cannot sell a stock before you buy one. 10 | 11 | Example 1: 12 | 13 | Input: [7,1,5,3,6,4] 14 | Output: 5 15 | Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5. 16 | Not 7-1 = 6, as selling price needs to be larger than buying price. 17 | Example 2: 18 | 19 | Input: [7,6,4,3,1] 20 | Output: 0 21 | Explanation: In this case, no transaction is done, i.e. max profit = 0. 22 | 23 | ''' 24 | 25 | # Kadanes algorithm with a twist - O(n) time, O(1) space 26 | def maxProfit(self, prices): 27 | max_profit_total, max_profit_current = 0, 0 28 | for i in range(1, len(prices)): 29 | max_profit_current = max(0, max_profit_current + prices[i] - prices[i-1]) 30 | max_profit_total = max(max_profit_current, max_profit_total) 31 | return max_profit_total 32 | -------------------------------------------------------------------------------- /leetcode/climbing_stairs.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 70. Climbing Stairs 4 | 5 | You are climbing a stair case. It takes n steps to reach to the top. 6 | 7 | Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? 8 | 9 | Note: Given n will be a positive integer. 10 | 11 | Example 1: 12 | 13 | Input: 2 14 | Output: 2 15 | Explanation: There are two ways to climb to the top. 16 | 1. 1 step + 1 step 17 | 2. 2 steps 18 | Example 2: 19 | 20 | Input: 3 21 | Output: 3 22 | Explanation: There are three ways to climb to the top. 23 | 1. 1 step + 1 step + 1 step 24 | 2. 1 step + 2 steps 25 | 3. 2 steps + 1 step 26 | 27 | ''' 28 | 29 | # Dynamic Programming Approach - O(n) time, O(n) space 30 | def climbStairs(self, n): 31 | if n == 1: return 1 32 | steps = [] 33 | steps[0] = 1 34 | steps[1] = 2 35 | for i in range(2, len(n)): 36 | steps[i] = steps[i-1] + steps[i-2] 37 | return steps[n-1] -------------------------------------------------------------------------------- /leetcode/contains_duplicate.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 127. Contains Duplicate 4 | 5 | Given an array of integers, find if the array contains any duplicates. 6 | 7 | Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct. 8 | 9 | Example 1: 10 | 11 | Input: [1,2,3,1] 12 | Output: true 13 | Example 2: 14 | 15 | Input: [1,2,3,4] 16 | Output: false 17 | Example 3: 18 | 19 | Input: [1,1,1,3,3,4,3,2,4,2] 20 | Output: true 21 | 22 | ''' 23 | 24 | # Normal approach - O(n) time, O(1) space 25 | def containsDuplicate(self, nums): 26 | seen = set() 27 | for item in nums: 28 | if item in seen: 29 | return True 30 | else: 31 | seen.add(item) 32 | return False 33 | -------------------------------------------------------------------------------- /leetcode/find_the_difference.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 389. Find the Difference 4 | 5 | Given two strings s and t which consist of only lowercase letters. 6 | 7 | String t is generated by random shuffling string s and then add one more letter at a random position. 8 | 9 | Find the letter that was added in t. 10 | 11 | Example: 12 | 13 | Input: 14 | s = "abcd" 15 | t = "abcde" 16 | 17 | Output: 18 | e 19 | 20 | Explanation: 21 | 'e' is the letter that was added. 22 | 23 | ''' 24 | 25 | # Initial solution - O(n) time, O(n) space 26 | def findTheDifference(self, s, t): 27 | d = {} 28 | for char in t: 29 | if char in d: 30 | d[char] += 1 31 | else: 32 | d[char] = 1 33 | 34 | for char in s: 35 | if char in d: 36 | d[char] -= 1 37 | 38 | for key, value in d.items(): 39 | if value > 0: 40 | return key 41 | 42 | 43 | -------------------------------------------------------------------------------- /leetcode/first_unique_char.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 387. First Unique Character in a String 4 | 5 | Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. 6 | 7 | Examples: 8 | 9 | s = "leetcode" 10 | return 0. 11 | 12 | s = "loveleetcode", 13 | return 2. 14 | Note: You may assume the string contain only lowercase letters. 15 | 16 | ''' 17 | 18 | # Dictionary Approach - O(n) time, O(n) space 19 | def firstUniqChar(self, s): 20 | seen = {} 21 | for item in s: 22 | if item not in seen: 23 | seen[item] = 1 24 | else: 25 | seen[item] += 1 26 | 27 | for i in range(len(s)): 28 | item = s[i] 29 | if seen[item] == 1: 30 | return i 31 | return -1 32 | 33 | 34 | -------------------------------------------------------------------------------- /leetcode/longest_common_prefix.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 14. Longest Common Prefix 4 | 5 | Write a function to find the longest common prefix string amongst an array of strings. 6 | 7 | If there is no common prefix, return an empty string "". 8 | 9 | Example 1: 10 | 11 | Input: ["flower","flow","flight"] 12 | Output: "fl" 13 | Example 2: 14 | 15 | Input: ["dog","racecar","car"] 16 | Output: "" 17 | Explanation: There is no common prefix among the input strings. 18 | Note: 19 | 20 | All given inputs are in lowercase letters a-z. 21 | 22 | ''' 23 | 24 | # Initial approach - O(n*i) time, O(n) space 25 | def longestCommonPrefix(self, strs): 26 | if (len(strs) == 0): return '' 27 | prefix = strs[0] 28 | for item in strs[1:]: 29 | if len(item) < len(prefix): 30 | prefix = item 31 | 32 | for item in strs: 33 | for i in range(len(prefix)): 34 | if item[i] != prefix[i]: 35 | prefix = prefix[:i] 36 | break 37 | 38 | return prefix 39 | -------------------------------------------------------------------------------- /leetcode/longest_palindrome.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 409. Longest Palindrome 4 | 5 | Given a string which consists of lowercase or uppercase letters, find the length of 6 | the longest palindromes that can be built with those letters. 7 | 8 | This is case sensitive, for example "Aa" is not considered a palindrome here. 9 | 10 | Note: 11 | Assume the length of given string will not exceed 1,010. 12 | 13 | Example: 14 | 15 | Input: 16 | "abccccdd" 17 | 18 | Output: 19 | 7 20 | 21 | Explanation: 22 | One longest palindrome that can be built is "dccaccd", whose length is 7. 23 | 24 | ''' 25 | 26 | # Dictionary approach - O(n) time, O(n) space 27 | def longestPalindrome(self, s): 28 | d = {} 29 | for char in s: 30 | if char in d: 31 | d[char] += 1 32 | else: 33 | d[char] = 1 34 | 35 | result, extra = 0, 0 36 | for key, value in d.items(): 37 | if value % 2 == 0: 38 | result += value 39 | else: 40 | result += value - 1 41 | extra = 1 42 | return result + extra -------------------------------------------------------------------------------- /leetcode/longest_palindromic_substring.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 5. Longest Palindromic Substring 4 | 5 | Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. 6 | 7 | Example 1: 8 | 9 | Input: "babad" 10 | Output: "bab" 11 | Note: "aba" is also a valid answer. 12 | 13 | Example 2: 14 | Input: "cbbd" 15 | Output: "bb" 16 | 17 | ''' 18 | 19 | # Brute force approach - O(n^3) time, O(1) space 20 | def longestPalindrome(self, s): 21 | longest_str = '' 22 | for i in range(len(s)): 23 | for j in range(i, len(s) + 1): 24 | temp = s[i:j] 25 | if temp == temp[::-1] and len(temp) >= len(longest_str): 26 | longest_str = temp 27 | return longest_str -------------------------------------------------------------------------------- /leetcode/majority_element.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. 4 | 5 | You may assume that the array is non-empty and the majority element always exist in the array. 6 | 7 | Example 1: 8 | 9 | Input: [3,2,3] 10 | Output: 3 11 | 12 | Example 2: 13 | Input: [2,2,1,1,1,2,2] 14 | Output: 2 15 | 16 | ''' 17 | 18 | # Dictionary approach - O(n) time, O(n) space 19 | def majorityElement(self, nums): 20 | d = {} 21 | for item in nums: 22 | if item in d: 23 | d[item] += 1 24 | else: 25 | d[item] = 1 26 | 27 | max_val = max_key = -1 28 | for key, value in d.items(): 29 | if value > (len(nums) // 2): 30 | return key 31 | -------------------------------------------------------------------------------- /leetcode/maximum_product_subarray.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 152. Maximum Product Subarray 4 | 5 | Given an integer array nums, find the contiguous subarray within an array (containing at least one number) 6 | which has the largest product. 7 | 8 | Example 1: 9 | 10 | Input: [2,3,-2,4] 11 | Output: 6 12 | Explanation: [2,3] has the largest product 6. 13 | Example 2: 14 | 15 | Input: [-2,0,-1] 16 | Output: 0 17 | Explanation: The result cannot be 2, because [-2,-1] is not a subarray. 18 | 19 | ''' 20 | 21 | # Kandane's with a twist - O(n) time, O(1) space --> WRONG 22 | def maxProduct(self, nums): 23 | count_neg = 0 24 | if not nums: 25 | return 0 26 | 27 | for item in nums: 28 | if item < 0: 29 | count_neg += 1 30 | 31 | if count_neg % 2 == 0: 32 | result = 1 33 | for item in nums: 34 | result *= item 35 | return result 36 | else: 37 | curr_max = nums[0] 38 | total_max = nums[0] 39 | 40 | for item in nums[1:]: 41 | curr_max = max(i, i * curr_max) 42 | total_max = max(total_max, curr_max) 43 | return total_max 44 | 45 | 46 | # Correct answer - O(n) time, O(1) space 47 | def maxProduct(self, nums): 48 | min_temp = nums[0] 49 | max_temp = nums[0] 50 | total_max = nums[0] 51 | for i in range(1, len(nums)): 52 | min_temp, max_temp = min(nums[i], nums[i] * max_temp, nums[i] * min_temp), max(nums[i], 53 | nums[i] * max_temp, nums[i] * min_temp) 54 | total_max = max(total_max, max_temp) 55 | return total_max 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /leetcode/maximum_subarray.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 53. Maximum Subarray 4 | 5 | Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. 6 | 7 | Example: 8 | 9 | Input: [-2,1,-3,4,-1,2,1,-5,4], 10 | Output: 6 11 | Explanation: [4,-1,2,1] has the largest sum = 6. 12 | Follow up: 13 | 14 | If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle. 15 | 16 | ''' 17 | 18 | # Kadane's Algorithm - O(n) time, O(1) space 19 | def maxSubArray(self, nums): 20 | total_max = nums[0] 21 | current_max = nums[0] 22 | for i in nums[1:]: 23 | current_max = max(i, current_max + i) 24 | total_max = max(total_max, current_max) 25 | return total_max -------------------------------------------------------------------------------- /leetcode/merge_sorted_array.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 88. Merge Sorted Array 4 | 5 | Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. 6 | 7 | Note: 8 | The number of elements initialized in nums1 and nums2 are m and n respectively. 9 | You may assume that nums1 has enough space (size that is greater or equal to m + n) to 10 | hold additional elements from nums2. 11 | 12 | Example: 13 | Input: 14 | nums1 = [1,2,3,0,0,0], m = 3 15 | nums2 = [2,5,6], n = 3 16 | 17 | Output: [1,2,2,3,5,6] 18 | 19 | ''' 20 | 21 | # Initial approach - O(?) time, O(?) space 22 | def merge(self, nums1, m, nums2, n): 23 | m, n = m - 1, n - 1 24 | while m >= 0 and n >= 0: 25 | if nums1[m] > nums2[n]: 26 | nums1[m + n + 1] = nums1[m] 27 | m -= 1 28 | else: 29 | nums1[m + n + 1] = nums2[n] 30 | n -= 1 31 | if n != -1: 32 | nums1[:n + 1] = nums2[:n + 1] -------------------------------------------------------------------------------- /leetcode/merge_sorted_linked_lists.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 21. Merge Two Sorted Lists 4 | 5 | Merge two sorted linked lists and return it as a new list. The new list should be made by 6 | splicing together the nodes of the first two lists. 7 | 8 | Example: 9 | 10 | Input: 1->2->4, 1->3->4 11 | Output: 1->1->2->3->4->4 12 | 13 | ''' 14 | 15 | # Two Pointer Approach - O(n) time, O(n) space 16 | def mergeTwoLists(self, l1, l2): 17 | result = currNode = ListNode(0) 18 | while l1 and l2: 19 | if l1.val > l2.val: 20 | currNode.next = l2 21 | l2 = l2.next 22 | else: 23 | currNode.next = l1 24 | l1 = l1.next 25 | currNode = currNode.next 26 | currNode.next = l1 or l2 27 | return result.next 28 | 29 | -------------------------------------------------------------------------------- /leetcode/missing_number.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 268. Missing Number 4 | 5 | Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. 6 | 7 | Example 1: 8 | 9 | Input: [3,0,1] 10 | Output: 2 11 | Example 2: 12 | 13 | Input: [9,6,4,2,3,5,7,0,1] 14 | Output: 8 15 | Note: 16 | Your algorithm should run in linear runtime complexity. Could you implement it using only constant extra space complexity? 17 | 18 | ''' 19 | 20 | # Store values - O(n) time, O(n) space 21 | def missingNumber(self, nums): 22 | max_num = -1 23 | seen = set() 24 | 25 | for item in nums: 26 | seen.add(item) 27 | if item > max_num: 28 | max_num = item 29 | 30 | for i in range(max_num): 31 | if i not in seen: 32 | return i 33 | return max_num + 1 34 | 35 | 36 | # Sort values - O(nlogn) time, O(1) space 37 | def missingNumber(self, nums): 38 | if len(nums) == 0: return 0 39 | nums.sort() 40 | for i in range(nums): 41 | if nums[i] != i: 42 | return nums[i] - 1 43 | return nums[-1] + 1 44 | 45 | 46 | -------------------------------------------------------------------------------- /leetcode/plus_one.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | Given a non-empty array of digits representing a non-negative integer, plus one to the integer. 4 | 5 | The digits are stored such that the most significant digit is at the head of the list, and each element 6 | in the array contain a single digit. 7 | 8 | You may assume the integer does not contain any leading zero, except the number 0 itself. 9 | 10 | Example 1: 11 | 12 | Input: [1,2,3] 13 | Output: [1,2,4] 14 | Explanation: The array represents the integer 123. 15 | Example 2: 16 | 17 | Input: [4,3,2,1] 18 | Output: [4,3,2,2] 19 | Explanation: The array represents the integer 4321. 20 | 21 | ''' 22 | 23 | # Standard approach - O(n) time, O(1) space 24 | def plusOne(self, digits): 25 | for i in range(len(digits) - 1, -1, -1): 26 | if digits[i] + 1 < 10: 27 | digits[i] += 1 28 | return digits 29 | else: 30 | digits[i] = 0 31 | 32 | return [1] + digits 33 | -------------------------------------------------------------------------------- /leetcode/remove_duplicates_linked_list.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 4 | 83. Remove Duplicates from Sorted List 5 | 6 | Given a sorted linked list, delete all duplicates such that each element appear only once. 7 | 8 | Example 1: 9 | 10 | Input: 1->1->2 11 | Output: 1->2 12 | Example 2: 13 | 14 | Input: 1->1->2->3->3 15 | Output: 1->2->3 16 | 17 | ''' 18 | 19 | # Standard approach - O(n) time, O(n) space 20 | def deleteDuplicates(self, head): 21 | curr = head 22 | while curr and curr.next: 23 | if curr.val == curr.next.val: 24 | curr.next = curr.next.next 25 | else: 26 | curr = curr.next 27 | 28 | return head 29 | 30 | 31 | -------------------------------------------------------------------------------- /leetcode/reverse_integer.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | Given a 32-bit signed integer, reverse digits of an integer. 4 | 5 | Example 1: 6 | 7 | Input: 123 8 | Output: 321 9 | Example 2: 10 | 11 | Input: -123 12 | Output: -321 13 | 14 | Example 3: 15 | 16 | Input: 120 17 | Output: 21 18 | 19 | Note: 20 | Assume we are dealing with an environment which could only store integers within the 32-bit 21 | signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your 22 | function returns 0 when the reversed integer overflows. 23 | 24 | ''' 25 | 26 | # Pythonic solution - O(n) time, O(n) space 27 | def reverse(self, x): 28 | if x > 0: 29 | sign = 1 30 | else: 31 | sign = -1 32 | result = int(str(abs(x))[::-1]) * sign 33 | return result if result > -(2**31) and result < (2**31) else 0 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /leetcode/reverse_vowels_string.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 345. Reverse Vowels of a String 4 | 5 | Write a function that takes a string as input and reverse only the vowels of a string. 6 | 7 | Example 1: 8 | 9 | Input: "hello" 10 | Output: "holle" 11 | 12 | Example 2: 13 | Input: "leetcode" 14 | Output: "leotcede" 15 | 16 | Note: 17 | The vowels does not include the letter "y". 18 | 19 | ''' 20 | 21 | # Initial approach - O(n) time, O(n) space 22 | def reverseVowels(self, s): 23 | vowels = {'e', 'i', 'o', 'u', 'a', 'A', 'E', 'I', 'O', 'U'} 24 | vowel_stack = [] 25 | for char in s: 26 | if char in vowels: 27 | vowel_stack.append(char) 28 | print(vowel_stack) 29 | s_list = list(s) 30 | for i in range(len(s_list)): 31 | if s_list[i] in vowels: 32 | s_list[i] = vowel_stack.pop() 33 | 34 | return ''.join(s_list) 35 | 36 | 37 | # Two pointer solution - O(n) time, O(n) space 38 | def reverseVowels(self, s): 39 | vowels = [i for i in range(len(s)) if s[i] in 'aeiouAEIOU'] 40 | s1 = list(s) 41 | for i in range(len(vowels)//2): 42 | s1[vowels[i]], s1[vowels[-i - 1]] = s1[vowels[-i - 1]], s1[vowels[i]] 43 | 44 | return ''.join(s1) 45 | 46 | 47 | -------------------------------------------------------------------------------- /leetcode/rotate_array.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 189. Rotate Array 4 | 5 | Given an array, rotate the array to the right by k steps, where k is non-negative. 6 | 7 | Example 1: 8 | 9 | Input: [1,2,3,4,5,6,7] and k = 3 10 | Output: [5,6,7,1,2,3,4] 11 | Explanation: 12 | rotate 1 steps to the right: [7,1,2,3,4,5,6] 13 | rotate 2 steps to the right: [6,7,1,2,3,4,5] 14 | rotate 3 steps to the right: [5,6,7,1,2,3,4] 15 | 16 | Example 2: 17 | 18 | Input: [-1,-100,3,99] and k = 2 19 | Output: [3,99,-1,-100] 20 | Explanation: 21 | rotate 1 steps to the right: [99,-1,-100,3] 22 | rotate 2 steps to the right: [3,99,-1,-100] 23 | Note: 24 | 25 | Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem. 26 | Could you do it in-place with O(1) extra space? 27 | 28 | ''' 29 | 30 | 31 | # Brute Force Approach - O(n*k) time, O(1) space 32 | def rotate(self, nums, k): 33 | temp, previous = 0, 0 34 | for i in range(k): 35 | previous = nums[-1] 36 | for j in range(len(nums)): 37 | temp = nums[j] 38 | nums[j] = previous 39 | previous = temp 40 | 41 | 42 | # Using Extra Array - O(n) time, O(n) space 43 | def rotate(self, nums, k): 44 | temp = [] 45 | for i in range(len(nums)): 46 | temp.append(nums[(i + k + 1) % len(nums)]) 47 | return temp[:] 48 | 49 | 50 | # Reverse Solution - O(n) time, O(1) space 51 | def rotate(self, nums, k): 52 | if k % len(nums) != 0: 53 | k = k % len(nums) 54 | nums[:] = nums[::-1][:k][::-1] + nums[::-1][k:][::-1] 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /leetcode/search_insert_position.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 35. Search Insert Position 4 | 5 | Given a sorted array and a target value, return the index if the target is found. If not, 6 | return the index where it would be if it were inserted in order. 7 | 8 | You may assume no duplicates in the array. 9 | 10 | Example 1: 11 | 12 | Input: [1,3,5,6], 5 13 | Output: 2 14 | Example 2: 15 | 16 | Input: [1,3,5,6], 2 17 | Output: 1 18 | Example 3: 19 | 20 | Input: [1,3,5,6], 7 21 | Output: 4 22 | Example 4: 23 | 24 | Input: [1,3,5,6], 0 25 | Output: 0 26 | 27 | ''' 28 | 29 | # Naive approach - O(n) time, O(1) space 30 | def searchInsert(self, nums, target): 31 | for i in range(len(nums)): 32 | if nums[i] == target: 33 | return i 34 | elif nums[i] > target: 35 | return i 36 | return len(nums) - 1 37 | 38 | 39 | # Binary search approach - O(logn) time, O(1) space 40 | def searchInsert(self, nums, target): 41 | low, high = 0, len(nums) - 1 42 | while low <= high: 43 | mid = (high + low) // 2 44 | if nums[mid] == target: 45 | return mid 46 | elif nums[mid] < target: 47 | low = mid + 1 48 | else: 49 | high = mid - 1 50 | return low 51 | 52 | 53 | -------------------------------------------------------------------------------- /leetcode/single_number.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 136. Single Number 4 | 5 | Given a non-empty array of integers, every element appears twice except for one. Find that single one. 6 | 7 | Note: 8 | 9 | Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? 10 | 11 | Example 1: 12 | Input: [2,2,1] 13 | Output: 1 14 | 15 | Example 2: 16 | Input: [4,1,2,1,2] 17 | Output: 4 18 | 19 | ''' 20 | 21 | # Dictionary approach - O(n) time, O(n) space 22 | def singleNumber(self, nums): 23 | d = {} 24 | for item in nums: 25 | if item in d: 26 | d[item] += 1 27 | else: 28 | d[item] = 1 29 | 30 | for key, value in d.items(): 31 | if value == 1: 32 | return key 33 | -------------------------------------------------------------------------------- /leetcode/string_compression.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 443. String Compression 4 | 5 | Given an array of characters, compress it in-place. 6 | 7 | The length after compression must always be smaller than or equal to the original array. 8 | 9 | Every element of the array should be a character (not int) of length 1. 10 | 11 | After you are done modifying the input array in-place, return the new length of the array. 12 | 13 | Follow up: 14 | Could you solve it using only O(1) extra space? 15 | 16 | Example 1: 17 | Input: 18 | ["a","a","b","b","c","c","c"] 19 | Output: 20 | Return 6, and the first 6 characters of the input array should be: ["a","2","b","2","c","3"] 21 | Explanation: 22 | "aa" is replaced by "a2". "bb" is replaced by "b2". "ccc" is replaced by "c3". 23 | 24 | Example 2: 25 | Input: 26 | ["a"] 27 | Output: 28 | Return 1, and the first 1 characters of the input array should be: ["a"] 29 | 30 | Explanation: 31 | Nothing is replaced. 32 | 33 | ''' 34 | 35 | # Initial approach - O(n) time, O(1) space 36 | def compress(self, chars): 37 | anchor = write = 0 38 | for read, c in enumerate(chars): 39 | if read + 1 == len(chars) or chars[read + 1] != c: 40 | chars[write] = chars[anchor] 41 | write += 1 42 | if read > anchor: 43 | for digit in str(read - anchor + 1): 44 | chars[write] = digit 45 | write += 1 46 | anchor = read + 1 47 | return write 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /leetcode/two_sum.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 1. Two Sum 4 | 5 | Given an array of integers, return indices of the two numbers such that they add up to a specific target. 6 | 7 | You may assume that each input would have exactly one solution, and you may not use the same element twice. 8 | 9 | Example: 10 | 11 | Given nums = [2, 7, 11, 15], target = 9, 12 | 13 | Because nums[0] + nums[1] = 2 + 7 = 9, 14 | return [0, 1]. 15 | 16 | ''' 17 | 18 | # Naive approach - O(n^2) time, O(1) space 19 | def twoSum(self, nums, target): 20 | for i in range(nums): 21 | for j in range(nums): 22 | if nums[i] + nums[j] == target and i != j: 23 | return i, j 24 | return -1 25 | 26 | 27 | # Set approach - O(n) time, O(n) space 28 | def twoSum(self, nums, target): 29 | num_dict = {} 30 | for i in range(len(nums)): 31 | if target - nums[i] in num_dict: 32 | return num_dict.get(target - nums[i]), i 33 | num_dict[nums[i]] = i 34 | return -1 -------------------------------------------------------------------------------- /leetcode/valid_palidrome.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 125. Valid Palindrome 4 | 5 | Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. 6 | 7 | Note: For the purpose of this problem, we define empty string as valid palindrome. 8 | 9 | Example 1: 10 | 11 | Input: "A man, a plan, a canal: Panama" 12 | Output: true 13 | 14 | Example 2: 15 | 16 | Input: "race a car" 17 | Output: false 18 | 19 | ''' 20 | 21 | # Simplest, Pythonic Approach - O(n) time, O(n) space 22 | def isPalindrome(self, s): 23 | s = [i.lower() for i in s if i.isalnum()] 24 | return s == s[::-1] -------------------------------------------------------------------------------- /leetcode/valid_parenthesis.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | 20. Valid Parenthesis 4 | 5 | Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. 6 | 7 | An input string is valid if: 8 | 9 | Open brackets must be closed by the same type of brackets. 10 | Open brackets must be closed in the correct order. 11 | Note that an empty string is also considered valid. 12 | 13 | Example 1: 14 | 15 | Input: "()" 16 | Output: true 17 | Example 2: 18 | 19 | Input: "()[]{}" 20 | Output: true 21 | Example 3: 22 | 23 | Input: "(]" 24 | Output: false 25 | Example 4: 26 | 27 | Input: "([)]" 28 | Output: false 29 | Example 5: 30 | 31 | Input: "{[]}[" 32 | Output: true 33 | 34 | ''' 35 | 36 | # Stack approach - O(n) time, O(n) space 37 | def isValid(self, s): 38 | def isValid(self, s): 39 | d = {'{':'}', '(':')', '[':']'} 40 | stack = [] 41 | for c in s: 42 | if c in d: 43 | stack.append(c) 44 | elif len(stack) == 0 or c != d[stack.pop()]: 45 | return False 46 | return len(stack) == 0 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /sql/sql_exercises1.sql: -------------------------------------------------------------------------------- 1 | 2 | -- Link to questions: https://en.wikibooks.org/wiki/SQL_Exercises/The_computer_store 3 | 4 | -- 1.1 Select the names of all the products in the store. 5 | SELECT name 6 | FROM products; 7 | 8 | 9 | -- 1.2 Select the names and the prices of all the products in the store. 10 | SELECT name, price 11 | FROM products; 12 | 13 | 14 | -- 1.3 Select the name of the products with a price less than or equal to $200. 15 | SELECT name 16 | FROM products 17 | WHERE price <= 200; 18 | 19 | 20 | -- 1.4 Select all the products with a price between $60 and $120. 21 | SELECT * 22 | FROM products 23 | WHERE price BETWEEN 60 AND 120; 24 | 25 | 26 | -- 1.5 Select the name and price in cents (i.e., the price must be multiplied by 100). 27 | SELECT name, price * 100 AS cents 28 | FROM products; 29 | 30 | 31 | -- 1.6 Compute the average price of all the products. 32 | SELECT AVG(price) 33 | FROM products; 34 | 35 | 36 | -- 1.7 Compute the average price of all products with manufacturer code equal to 2. 37 | SELECT AVG(price) 38 | FROM products 39 | WHERE manufacturer = 2; 40 | 41 | 42 | -- 1.8 Compute the number of products with a price larger than or equal to $180. 43 | SELECT COUNT(*) 44 | FROM products 45 | WHERE price >= 180; 46 | 47 | 48 | -- 1.9 Select the name and price of all products with a price larger than or equal to $180, 49 | -- and sort first by price (in descending order), and then by name (in ascending order). 50 | SELECT name, price 51 | FROM products 52 | WHERE price >= 180 53 | ORDER BY price DESC, name ASC; 54 | 55 | 56 | -- 1.10 Select all the data from the products, including all the data for each product's manufacturer. 57 | SELECT * 58 | FROM products a JOIN manufacturers b 59 | ON a.manufacturer = b.code; 60 | 61 | 62 | -- 1.11 Select the product name, price, and manufacturer name of all the products. 63 | SELECT a.name, a.price, b.name 64 | FROM products a JOIN manufacturers b 65 | ON a.manufacturer = b.code; 66 | 67 | 68 | -- 1.12 Select the average price of each manufacturer's products, showing only the manufacturer's code. 69 | SELECT manufacturer, AVG(price) 70 | FROM products 71 | GROUP BY manufacturer; 72 | 73 | 74 | -- 1.13 Select the average price of each manufacturer's products, showing the manufacturer's name. 75 | SELECT b.name, AVG(a.price) 76 | FROM products a JOIN manufacturers b 77 | ON a.manufacturer = b.code 78 | GROUP BY b.name; 79 | 80 | 81 | -- 1.14 Select the names of manufacturer whose products have an average price larger than or equal to $150. 82 | SELECT b.name 83 | FROM products a JOIN manufacturers b 84 | ON a.manufacturer = b.code 85 | GROUP BY b.name 86 | HAVING AVG(a.price) >= 150; 87 | 88 | 89 | -- 1.15 Select the name and price of the cheapest product. ***** 90 | SELECT name, price 91 | FROM products 92 | WHERE price = (SELECT MIN(price) FROM products); 93 | 94 | SELECT name, price 95 | FROM products 96 | ORDER BY price ASC 97 | LIMIT 1; 98 | 99 | -- 1.16 Select the name of each manufacturer along with the name and price of its most expensive product. ***** 100 | SELECT b.name, a.name, a.price 101 | FROM products a JOIN manufacturers b 102 | ON a.manufacturer = b.code 103 | AND a.price = (SELECT MAX(a.price) 104 | FROM products a 105 | WHERE a.manufacturer = b.code); 106 | 107 | 108 | -- 1.17 Add a new product: Loudspeakers, $70, manufacturer 2. 109 | INSERT INTO products( code, name, price, manufacturer) 110 | VALUES (11, 'Loudspeakers', 70, 2); 111 | 112 | 113 | -- 1.18 Update the name of product 8 to "Laser Printer". 114 | UPDATE products 115 | SET name = 'Laser Printer' 116 | WHERE code = 8; 117 | 118 | 119 | -- 1.19 Apply a 10% discount to all products. 120 | UPDATE products 121 | SET price = price - (price * 0.1); 122 | 123 | 124 | -- 1.20 Apply a 10% discount to all products with a price larger than or equal to $120. 125 | UPDATE products 126 | SET price = price - (price * 0.1) 127 | WHERE price >= 120; 128 | 129 | 130 | -------------------------------------------------------------------------------- /sql/sql_exercises2.sql: -------------------------------------------------------------------------------- 1 | 2 | -- Link to questions: https://en.wikibooks.org/wiki/SQL_Exercises/Employee_management 3 | 4 | -- 2.1 Select the last name of all employees. 5 | SELECT lastname 6 | FROM employees; 7 | 8 | 9 | -- 2.2 Select the last name of all employees, without duplicates. 10 | SELECT DISTINCT lastname 11 | FROM employees; 12 | 13 | 14 | -- 2.3 Select all the data of employees whose last name is "Smith". 15 | SELECT * 16 | FROM employees 17 | WHERE lastname = 'Smith'; 18 | 19 | 20 | -- 2.4 Select all the data of employees whose last name is "Smith" or "Doe". 21 | SELECT * 22 | FROM employees 23 | WHERE lastname IN ('Smith', 'Doe'); 24 | 25 | 26 | -- 2.5 Select all the data of employees that work in department 14. 27 | SELECT * 28 | FROM employees 29 | WHERE department = 14; 30 | 31 | 32 | -- 2.6 Select all the data of employees that work in department 37 or department 77. 33 | SELECT * 34 | FROM employees 35 | WHERE department IN (37, 77); 36 | 37 | 38 | -- 2.7 Select all the data of employees whose last name begins with an "S". 39 | SELECT * 40 | FROM employees 41 | WHERE lastname LIKE 'S%'; 42 | 43 | 44 | -- 2.8 Select the sum of all the departments' budgets. 45 | SELECT SUM(budget) 46 | FROM departments; 47 | 48 | 49 | -- 2.9 Select the number of employees in each department (you only need to show the department 50 | -- code and the number of employees). 51 | SELECT department, COUNT(*) 52 | FROM employees 53 | GROUP BY department; 54 | 55 | 56 | -- 2.10 Select all the data of employees, including each employee's department's data. 57 | SELECT * 58 | FROM employees a JOIN departments b 59 | ON a.department = b.code; 60 | 61 | 62 | -- 2.11 Select the name and last name of each employee, along with the name and budget of the employee's department. 63 | SELECT a.name, a.lastname, b.name, b.budget 64 | FROM employees a JOIN departments b 65 | ON a.department = b.code; 66 | 67 | 68 | -- 2.12 Select the name and last name of employees working for departments with a budget greater than $60,000. 69 | SELECT a.name, a.lastname 70 | FROM employees a JOIN departments b 71 | ON a.department = b.code AND b.budget > 60000; 72 | 73 | 74 | -- 2.13 Select the departments with a budget larger than the average budget of all the departments. 75 | SELECT * 76 | FROM departments 77 | WHERE budget > (SELECT AVG(budget) 78 | FROM departments); 79 | 80 | 81 | -- 2.14 Select the names of departments with more than two employees. 82 | SELECT b.name 83 | FROM employees a JOIN departments b 84 | ON a.department = b.code 85 | WHERE b.name IN (SELECT department 86 | FROM employees 87 | GROUP BY department 88 | HAVING COUNT(*) > 2); 89 | 90 | 91 | -- 2.15 Very Important - Select the name and last name of employees working for departments with second lowest budget. 92 | SELECT name, lastname 93 | FROM employees 94 | WHERE department = (SELECT code 95 | FROM (SELECT * 96 | FROM department 97 | ORDER BY budget ASC 98 | LIMIT 2) 99 | ORDER BY budget DESC 100 | LIMIT 1); 101 | 102 | 103 | -- 2.16 Add a new department called "Quality Assurance", with a budget of $40,000 and departmental code 11. 104 | INSERT INTO departments(code, name, budget) 105 | VALUES (11, 'Quality Assurance', 40000); 106 | 107 | 108 | -- And Add an employee called "Mary Moore" in that department, with SSN 847-21-9811. 109 | INSERT INTO employees(ssn, name, lastname, department) 110 | VALUES (847219811, 'Mary', 'Moore', 11); 111 | 112 | 113 | -- 2.17 Reduce the budget of all departments by 10%. 114 | UPDATE departments 115 | SET budget = budget - budget * (0.10); 116 | 117 | 118 | -- 2.18 Reassign all employees from the Research department (code 77) to the IT department (code 14). 119 | UPDATE employees 120 | SET department = 14 WHERE department = 77; 121 | 122 | 123 | -- 2.19 Delete from the table all employees in the IT department (code 14). 124 | DELETE FROM employees 125 | WHERE department = 14; 126 | 127 | 128 | -- 2.20 Delete from the table all employees who work in departments with a budget greater than or equal to $60,000. 129 | DELETE FROM employees 130 | WHERE department IN 131 | (SELECT code FROM departments 132 | WHERE budget >= 60000); 133 | 134 | 135 | -- 2.21 Delete from the table all employees. 136 | DELETE FROM employees; 137 | 138 | 139 | -------------------------------------------------------------------------------- /sql/sql_exercises3.sql: -------------------------------------------------------------------------------- 1 | 2 | 3 | -- Link: https://en.wikibooks.org/wiki/SQL_Exercises/The_warehouse 4 | 5 | -- 3.1 Select all warehouses. 6 | SELECT * 7 | FROM warehouses; 8 | 9 | 10 | -- 3.2 Select all boxes with a value larger than $150. 11 | SELECT * 12 | FROM boxes 13 | WHERE value > 150; 14 | 15 | 16 | -- 3.3 Select all distinct contents in all the boxes. 17 | SELECT DISTINCT contents 18 | FROM boxes; 19 | 20 | 21 | -- 3.4 Select the average value of all the boxes. 22 | SELECT AVG(value) 23 | FROM boxes; 24 | 25 | 26 | -- 3.5 Select the warehouse code and the average value of the boxes in each warehouse. 27 | SELECT warehouse, AVG(value) 28 | FROM boxes 29 | GROUP BY warehouse; 30 | 31 | 32 | -- 3.6 Same as previous exercise, but select only those warehouses where the average value of the boxes is 33 | -- greater than 150. 34 | SELECT warehouse, AVG(value) 35 | FROM boxes 36 | GROUP BY warehouse 37 | HAVING AVG(value) > 150; 38 | 39 | 40 | -- 3.7 Select the code of each box, along with the name of the city the box is located in. 41 | SELECT a.code, b.location 42 | FROM boxes a JOIN warehouses b 43 | ON a.warehouse = b.code; 44 | 45 | 46 | -- 3.8 Select the warehouse codes, along with the number of boxes in each warehouse. 47 | -- Optionally, take into account that some warehouses are empty (i.e., the box count should show up as zero, 48 | -- instead of omitting the warehouse from the result). 49 | SELECT b.code, COUNT(*) AS num 50 | FROM boxes a LEFT JOIN warehouses b 51 | ON a.warehouse = b.code 52 | GROUP BY b.code; 53 | 54 | 55 | -- 3.9 Select the codes of all warehouses that are saturated (a warehouse is 56 | -- saturated if the number of boxes in it is larger than the warehouse's capacity). 57 | SELECT b.code 58 | FROM boxes a JOIN warehouses b 59 | ON a.warehouse = b.code 60 | GROUP BY b.code 61 | HAVING COUNT(a.code) > b.capacity; 62 | 63 | 64 | -- 3.10 Select the codes of all the boxes located in Chicago. 65 | SELECT a.code 66 | FROM boxes a RIGHT JOIN warehouses b 67 | ON a.warehouse = b.code 68 | WHERE b.location = 'Chicago'; 69 | 70 | 71 | -- 3.11 Create a new warehouse in New York with a capacity for 3 boxes. 72 | INSERT INTO warehouses(location, capacity) 73 | VALUES ('New York', 3); 74 | 75 | 76 | -- 3.12 Create a new box, with code "H5RT", containing "Papers" with a value of $200, and located in warehouse 2. 77 | INSERT INTO boxes 78 | VALUES ('H5RT', 'Papers', 200, 2); 79 | 80 | -- 3.13 Reduce the value of all boxes by 15%. 81 | UPDATE boxes 82 | SET value = value * 0.85 83 | 84 | 85 | -- 3.14 Remove all boxes with a value lower than $100. 86 | DELETE FROM boxes 87 | WHERE value < 100; 88 | 89 | 90 | -- 3.15 Remove all boxes from saturated warehouses. 91 | DELETE FROM boxes 92 | WHERE warehouse IN 93 | (SELECT b.code 94 | FROM boxes a JOIN warehouses b 95 | ON a.warehouse = b.code 96 | GROUP BY b.code 97 | HAVING COUNT(*) > b.capacity); 98 | 99 | 100 | -------------------------------------------------------------------------------- /sql/sql_exercises4.sql: -------------------------------------------------------------------------------- 1 | 2 | -- Link: https://en.wikibooks.org/wiki/SQL_Exercises/Movie_theatres 3 | 4 | -- 4.1 Select the title of all movies. 5 | SELECT title 6 | FROM movies; 7 | 8 | 9 | -- 4.2 Show all the distinct ratings in the database. 10 | SELECT DISTINCT rating 11 | FROM movies; 12 | 13 | 14 | -- 4.3 Show all unrated movies. 15 | SELECT title 16 | FROM movies 17 | WHERE rating IS NULL; 18 | 19 | 20 | -- 4.4 Select all movie theaters that are not currently showing a movie. 21 | SELECT * 22 | FROM movietheaters 23 | WHERE movie IS NULL; 24 | 25 | 26 | -- 4.5 Select all data from all movie theaters 27 | -- and, additionally, the data from the movie that is being shown in the theater (if one is being shown). 28 | SELECT * 29 | FROM movietheaters a LEFT JOIN movies b 30 | ON a.movie = b.code 31 | 32 | 33 | -- 4.6 Select all data from all movies and, if that movie is being shown in a theater, show the data from the theater. 34 | SELECT * 35 | FROM movietheaters a RIGHT JOIN movies b 36 | ON a.movie = b.code 37 | 38 | 39 | -- 4.7 Show the titles of movies not currently being shown in any theaters. 40 | SELECT title 41 | FROM movies 42 | WHERE code NOT IN (SELECT movie 43 | FROM movietheaters 44 | WHERE movie IS NOT NULL); 45 | 46 | 47 | -- 4.8 Add the unrated movie "One, Two, Three". 48 | INSERT INTO movies(title, rating) 49 | VALUES('One, Two, Three', 'unrated'); 50 | 51 | 52 | -- 4.9 Set the rating of all unrated movies to "G". 53 | UPDATE movies 54 | SET rating = 'G' 55 | WHERE rating IS NULL 56 | 57 | 58 | -- 4.10 Remove movie theaters projecting movies rated "NC-17". 59 | DELETE FROM movietheaters 60 | WHERE movie IN (SELECT code 61 | FROM movies 62 | WHERE rating = 'NC-17'); 63 | 64 | -------------------------------------------------------------------------------- /sql/sql_exercises5.sql: -------------------------------------------------------------------------------- 1 | 2 | -- Link: https://en.wikibooks.org/wiki/SQL_Exercises/Pieces_and_providers 3 | 4 | -- 5.1 Select the name of all the pieces. 5 | SELECT name 6 | FROM pieces; 7 | 8 | 9 | -- 5.2 Select all the providers' data. 10 | SELECT * 11 | FROM providers; 12 | 13 | 14 | -- 5.3 Obtain the average price of each piece (show only the piece code and the average price). 15 | SELECT piece, AVG(price) 16 | FROM provides 17 | GROUP BY piece; 18 | 19 | 20 | -- 5.4 Obtain the names of all providers who supply piece 1. 21 | SELECT b.name 22 | FROM provides a JOIN providers b 23 | ON a.provider = b.code 24 | WHERE a.piece = 1; 25 | 26 | 27 | -- 5.5 Select the name of pieces provided by provider with code "HAL". 28 | SELECT b.name 29 | FROM provides a JOIN pieces b 30 | ON a.piece = b.code 31 | WHERE a.provider = 'HAL'; 32 | 33 | 34 | -- 5.6 For each piece, find the most expensive offering of that piece and include the piece name, provider name, and price 35 | -- (note that there could be two providers who supply the same piece at the most expensive price). 36 | SELECT b.name, c.name, a.price 37 | FROM provides a JOIN pieces b 38 | ON a.piece = b.code JOIN providers c 39 | ON a.provider = c.code 40 | WHERE a.price = (SELECT MAX(price) 41 | FROM provides 42 | WHERE piece = b.code); 43 | 44 | 45 | -- 5.7 Add an entry to the database to indicate that "Skellington Supplies" (code "TNBC") will provide sprockets (code "1") for 7 cents each. 46 | 47 | 48 | -- 5.8 Increase all prices by one cent. 49 | 50 | 51 | -- 5.9 Update the database to reflect that "Susan Calvin Corp." (code "RBT") will not supply bolts (code 4). 52 | 53 | 54 | -- 5.10 Update the database to reflect that "Susan Calvin Corp." (code "RBT") will not supply any pieces 55 | -- (the provider should still remain in the database). --------------------------------------------------------------------------------