ST-1 Project (2210992098)¶
LeetCode is an online platform for coding interview preparation. The service provides coding and algorithmic problems intended for users to practice coding.¶
Website : Click here to go to LeetCode¶
Data Dictionary :¶
id: problem id
title: problem name
description: problem description
is_premium: whether the questions requires a premium account
difficulty: easy, medium, or hect
acceptance_rate: how often the answer submitted is correct
frequency: how often the problem is attempted
url: url to the problem
discuss_count: how many comments are submitted by users
accepted: how many times the answer was accepted
submissions: how many times the answer was submitted
companies: which companies were tagged as having asked this specific problem
related_topics: related topics to the current problem
likes: how many likes the problem got
dislikes: how many dislikes the problem got
rating: likes / (likes + dislikes)
asked_by_faang: whether or not the question was asked by facebook, apple, amazon, google, or netflix
similar_questions: similar problems with problem name, slug, and difficulty
Importing Libraries and Ignoring warnings¶
#Importing libraries
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import re #regular expression
import warnings
# Suppress all warnings
warnings.filterwarnings("ignore")
Load dataset¶
# Load the dataset
data = pd.read_csv('csvfile.csv')
data
| id | title | description | is_premium | difficulty | solution_link | acceptance_rate | frequency | url | discuss_count | accepted | submissions | companies | related_topics | likes | dislikes | rating | asked_by_faang | similar_questions | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | Two Sum | Given an array of integers `nums` and an integ... | 0 | Easy | /articles/two-sum | 46.7 | 100.0 | https://leetcode.com/problems/two-sum | 999.0 | 4.1M | 8.7M | Amazon,Google,Apple,Adobe,Microsoft,Bloomberg,... | Array,Hash Table | 20217 | 712 | 97 | 1 | [3Sum, /problems/3sum/, Medium], [4Sum, /probl... |
| 1 | 2 | Add Two Numbers | You are given two non-empty linked lists repre... | 0 | Medium | NaN | 35.7 | 93.1 | https://leetcode.com/problems/add-two-numbers | 999.0 | 1.9M | 5.2M | Bloomberg,Microsoft,Amazon,Google,Facebook,App... | Linked List,Math,Recursion | 11350 | 2704 | 81 | 1 | [Multiply Strings, /problems/multiply-strings/... |
| 2 | 3 | Longest Substring Without Repeating Characters | Given a string `s`, find the length of the lon... | 0 | Medium | /articles/longest-substring-without-repeating-... | NaN | 90.9 | https://leetcode.com/problems/longest-substrin... | 999.0 | 2.1M | 6.7M | NaN | Hash Table,Two Pointers,String,Sliding Window | 13810 | 714 | 95 | 1 | [Longest Substring with At Most Two Distinct C... |
| 3 | 4 | Median of Two Sorted Arrays | Given two sorted arrays `nums1` and `nums2` of... | 0 | Hard | /articles/median-of-two-sorted-arrays | 31.4 | NaN | https://leetcode.com/problems/median-of-two-so... | 999.0 | 904.7K | 2.9M | Amazon,Goldman Sachs,Facebook,Microsoft,Apple,... | Array,Binary Search,Divide and Conquer | 9665 | 1486 | 87 | 1 | NaN |
| 4 | 5 | Longest Palindromic Substring | Given a string `s`, return the longest palindr... | 0 | Medium | /articles/longest-palindromic-substring | 30.6 | 84.7 | https://leetcode.com/problems/longest-palindro... | NaN | 1.3M | NaN | Amazon,Microsoft,Wayfair,Facebook,Adobe,eBay,G... | String,Dynamic Programming | 10271 | 670 | 94 | 1 | [Shortest Palindrome, /problems/shortest-palin... |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 1820 | 1821 | Find Customers With Positive Revenue this Year | SQL Schema | 1 | Easy | NaN | 88.9 | 0.0 | https://leetcode.com/problems/find-customers-w... | 15.0 | 305 | 343 | NaN | 2 | 2 | 50 | 1 | NaN | |
| 1821 | 1822 | Sign of the Product of an Array | There is a function `signFunc(x)` that returns... | 0 | Easy | NaN | 67.8 | 0.0 | https://leetcode.com/problems/sign-of-the-prod... | 104.0 | 7.9K | 11.7K | Microsoft | Math | 37 | 4 | 90 | 0 | NaN |
| 1822 | 1823 | Find the Winner of the Circular Game | There are `n` friends that are playing a game.... | 0 | Medium | NaN | 71.8 | 0.0 | https://leetcode.com/problems/find-the-winner-... | 135.0 | 6.8K | 9.5K | Bloomberg | Array | 81 | 4 | 95 | 0 | NaN |
| 1823 | 1824 | Minimum Sideway Jumps | There is a 3 lane road of length `n` that cons... | 0 | Medium | NaN | 47.2 | 0.0 | https://leetcode.com/problems/minimum-sideway-... | 134.0 | 5K | 10.7K | Pony.ai | Dynamic Programming,Breadth-first Search | 147 | 8 | 95 | 0 | [Frog Jump, /problems/frog-jump/, Hard] |
| 1824 | 1825 | Finding MK Average | You are given two integers, `m` and `k`, and a... | 0 | Hard | NaN | 28.1 | 0.0 | https://leetcode.com/problems/finding-mk-average | 48.0 | 2.1K | 7.4K | Heap,Design,Queue | 52 | 43 | 55 | 1 | [Find Median from Data Stream, /problems/find-... |
1825 rows × 19 columns
# Check the null values
data.isna()
| id | title | description | is_premium | difficulty | solution_link | acceptance_rate | frequency | url | discuss_count | accepted | submissions | companies | related_topics | likes | dislikes | rating | asked_by_faang | similar_questions | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False |
| 1 | False | False | False | False | False | True | False | False | False | False | False | False | False | False | False | False | False | False | False |
| 2 | False | False | False | False | False | False | True | False | False | False | False | False | True | False | False | False | False | False | False |
| 3 | False | False | False | False | False | False | False | True | False | False | False | False | False | False | False | False | False | False | True |
| 4 | False | False | False | False | False | False | False | False | False | True | False | True | False | False | False | False | False | False | False |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 1820 | False | False | False | False | False | True | False | False | False | False | False | False | False | True | False | False | False | False | True |
| 1821 | False | False | False | False | False | True | False | False | False | False | False | False | False | False | False | False | False | False | True |
| 1822 | False | False | False | False | False | True | False | False | False | False | False | False | False | False | False | False | False | False | True |
| 1823 | False | False | False | False | False | True | False | False | False | False | False | False | False | False | False | False | False | False | False |
| 1824 | False | False | False | False | False | True | False | False | False | False | False | False | False | False | False | False | False | False | False |
1825 rows × 19 columns
# Drop rows with missing values if necessary
data.dropna()
| id | title | description | is_premium | difficulty | solution_link | acceptance_rate | frequency | url | discuss_count | accepted | submissions | companies | related_topics | likes | dislikes | rating | asked_by_faang | similar_questions | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | Two Sum | Given an array of integers `nums` and an integ... | 0 | Easy | /articles/two-sum | 46.7 | 100.0 | https://leetcode.com/problems/two-sum | 999.0 | 4.1M | 8.7M | Amazon,Google,Apple,Adobe,Microsoft,Bloomberg,... | Array,Hash Table | 20217 | 712 | 97 | 1 | [3Sum, /problems/3sum/, Medium], [4Sum, /probl... |
| 7 | 8 | String to Integer (atoi) | Implement the `myAtoi(string s)` function, whi... | 0 | Medium | /articles/string-to-integer | 15.7 | 56.0 | https://leetcode.com/problems/string-to-intege... | 999.0 | 716.1K | 4.6M | Facebook,Amazon,Microsoft,Google,Goldman Sachs... | Math,String | 189 | 479 | 28 | 1 | [Reverse Integer, /problems/reverse-integer/, ... |
| 9 | 10 | Regular Expression Matching | Given an input string (`s`) and a pattern (`p`... | 0 | Hard | /articles/regular-expression-matching | 27.4 | 75.0 | https://leetcode.com/problems/regular-expressi... | 999.0 | 526.6K | 1.9M | Facebook,Amazon,Microsoft,Google,Adobe,Courser... | String,Dynamic Programming,Backtracking | 5583 | 841 | 87 | 1 | [Wildcard Matching, /problems/wildcard-matchin... |
| 11 | 12 | Integer to Roman | Roman numerals are represented by seven differ... | 0 | Medium | /articles/integer-to-roman | 57.1 | 41.8 | https://leetcode.com/problems/integer-to-roman | 999.0 | 474.6K | 831.1K | Amazon,Bloomberg,Microsoft,Adobe,Google,Apple,... | Math,String | 1675 | 3112 | 35 | 1 | [Roman to Integer, /problems/roman-to-integer/... |
| 12 | 13 | Roman to Integer | Roman numerals are represented by seven differ... | 0 | Easy | /articles/roman-to-integer | 57.0 | 60.5 | https://leetcode.com/problems/roman-to-integer | 999.0 | 947.4K | 1.7M | Amazon,Roblox,Microsoft,Adobe,Facebook,LinkedI... | Math,String | 419 | 40 | 91 | 1 | [Integer to Roman, /problems/integer-to-roman/... |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 1678 | 1679 | Max Number of K-Sum Pairs | You are given an integer array `nums` and an i... | 0 | Medium | /articles/max-number-of-k-sum-pairs | 53.9 | 16.2 | https://leetcode.com/problems/max-number-of-k-... | 381.0 | 36.4K | 67.7K | DE Shaw | Hash Table | 400 | 17 | 96 | 0 | [Two Sum, /problems/two-sum/, Easy], [Count Go... |
| 1689 | 1690 | Stone Game VII | Alice and Bob take turns playing a game, with ... | 0 | Medium | /articles/stone-game-vii | 49.0 | 2.5 | https://leetcode.com/problems/stone-game-vii | 142.0 | 7.1K | 14.5K | Dunzo | Dynamic Programming | 214 | 71 | 75 | 0 | [Stone Game, /problems/stone-game/, Medium], [... |
| 1694 | 1695 | Maximum Erasure Value | You are given an array of positive integers `n... | 0 | Medium | /articles/maximum-erasure-value | 49.4 | 6.6 | https://leetcode.com/problems/maximum-erasure-... | 198.0 | 11.8K | 23.9K | Cashfree | Two Pointers | 223 | 7 | 97 | 0 | [Longest Substring Without Repeating Character... |
| 1695 | 1696 | Jump Game VI | You are given a 0-indexed integer array `nums`... | 0 | Medium | /articles/jump-game-vi | 51.8 | 12.3 | https://leetcode.com/problems/jump-game-vi | 162.0 | 12.3K | 23.7K | Uber | Dequeue | 341 | 21 | 94 | 0 | [Sliding Window Maximum, /problems/sliding-win... |
| 1720 | 1721 | Swapping Nodes in a Linked List | You are given the `head` of a linked list, and... | 0 | Medium | /articles/swapping-nodes-in-a-linked-list | 67.6 | 1.0 | https://leetcode.com/problems/swapping-nodes-i... | 413.0 | 44.6K | 66K | Amazon | Linked List | 472 | 35 | 93 | 1 | [Remove Nth Node From End of List, /problems/r... |
553 rows × 19 columns
# Display top 5
data.head()
| id | title | description | is_premium | difficulty | solution_link | acceptance_rate | frequency | url | discuss_count | accepted | submissions | companies | related_topics | likes | dislikes | rating | asked_by_faang | similar_questions | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | Two Sum | Given an array of integers `nums` and an integ... | 0 | Easy | /articles/two-sum | 46.7 | 100.0 | https://leetcode.com/problems/two-sum | 999.0 | 4.1M | 8.7M | Amazon,Google,Apple,Adobe,Microsoft,Bloomberg,... | Array,Hash Table | 20217 | 712 | 97 | 1 | [3Sum, /problems/3sum/, Medium], [4Sum, /probl... |
| 1 | 2 | Add Two Numbers | You are given two non-empty linked lists repre... | 0 | Medium | NaN | 35.7 | 93.1 | https://leetcode.com/problems/add-two-numbers | 999.0 | 1.9M | 5.2M | Bloomberg,Microsoft,Amazon,Google,Facebook,App... | Linked List,Math,Recursion | 11350 | 2704 | 81 | 1 | [Multiply Strings, /problems/multiply-strings/... |
| 2 | 3 | Longest Substring Without Repeating Characters | Given a string `s`, find the length of the lon... | 0 | Medium | /articles/longest-substring-without-repeating-... | NaN | 90.9 | https://leetcode.com/problems/longest-substrin... | 999.0 | 2.1M | 6.7M | NaN | Hash Table,Two Pointers,String,Sliding Window | 13810 | 714 | 95 | 1 | [Longest Substring with At Most Two Distinct C... |
| 3 | 4 | Median of Two Sorted Arrays | Given two sorted arrays `nums1` and `nums2` of... | 0 | Hard | /articles/median-of-two-sorted-arrays | 31.4 | NaN | https://leetcode.com/problems/median-of-two-so... | 999.0 | 904.7K | 2.9M | Amazon,Goldman Sachs,Facebook,Microsoft,Apple,... | Array,Binary Search,Divide and Conquer | 9665 | 1486 | 87 | 1 | NaN |
| 4 | 5 | Longest Palindromic Substring | Given a string `s`, return the longest palindr... | 0 | Medium | /articles/longest-palindromic-substring | 30.6 | 84.7 | https://leetcode.com/problems/longest-palindro... | NaN | 1.3M | NaN | Amazon,Microsoft,Wayfair,Facebook,Adobe,eBay,G... | String,Dynamic Programming | 10271 | 670 | 94 | 1 | [Shortest Palindrome, /problems/shortest-palin... |
# Display last 5
data.tail()
| id | title | description | is_premium | difficulty | solution_link | acceptance_rate | frequency | url | discuss_count | accepted | submissions | companies | related_topics | likes | dislikes | rating | asked_by_faang | similar_questions | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1820 | 1821 | Find Customers With Positive Revenue this Year | SQL Schema | 1 | Easy | NaN | 88.9 | 0.0 | https://leetcode.com/problems/find-customers-w... | 15.0 | 305 | 343 | NaN | 2 | 2 | 50 | 1 | NaN | |
| 1821 | 1822 | Sign of the Product of an Array | There is a function `signFunc(x)` that returns... | 0 | Easy | NaN | 67.8 | 0.0 | https://leetcode.com/problems/sign-of-the-prod... | 104.0 | 7.9K | 11.7K | Microsoft | Math | 37 | 4 | 90 | 0 | NaN |
| 1822 | 1823 | Find the Winner of the Circular Game | There are `n` friends that are playing a game.... | 0 | Medium | NaN | 71.8 | 0.0 | https://leetcode.com/problems/find-the-winner-... | 135.0 | 6.8K | 9.5K | Bloomberg | Array | 81 | 4 | 95 | 0 | NaN |
| 1823 | 1824 | Minimum Sideway Jumps | There is a 3 lane road of length `n` that cons... | 0 | Medium | NaN | 47.2 | 0.0 | https://leetcode.com/problems/minimum-sideway-... | 134.0 | 5K | 10.7K | Pony.ai | Dynamic Programming,Breadth-first Search | 147 | 8 | 95 | 0 | [Frog Jump, /problems/frog-jump/, Hard] |
| 1824 | 1825 | Finding MK Average | You are given two integers, `m` and `k`, and a... | 0 | Hard | NaN | 28.1 | 0.0 | https://leetcode.com/problems/finding-mk-average | 48.0 | 2.1K | 7.4K | Heap,Design,Queue | 52 | 43 | 55 | 1 | [Find Median from Data Stream, /problems/find-... |
Getting Info and Describe about Dataset¶
#Get describe
data.describe()
| id | is_premium | acceptance_rate | frequency | discuss_count | likes | dislikes | rating | asked_by_faang | |
|---|---|---|---|---|---|---|---|---|---|
| count | 1825.000000 | 1825.000000 | 1824.000000 | 1824.000000 | 1823.000000 | 1825.000000 | 1825.000000 | 1825.000000 | 1825.000000 |
| mean | 913.000000 | 0.218082 | 53.151480 | 21.077357 | 420.801426 | 1050.534795 | 279.010959 | 77.391233 | 0.671233 |
| std | 526.976438 | 0.413057 | 14.773768 | 22.318847 | 330.210414 | 1512.674013 | 608.489206 | 23.317515 | 0.469894 |
| min | 1.000000 | 0.000000 | 13.900000 | 0.000000 | 9.000000 | 2.000000 | 0.000000 | 7.000000 | 0.000000 |
| 25% | 457.000000 | 0.000000 | 42.400000 | 3.100000 | 150.000000 | 217.000000 | 32.000000 | 67.000000 | 0.000000 |
| 50% | 913.000000 | 0.000000 | 51.650000 | 13.500000 | 291.000000 | 516.000000 | 92.000000 | 88.000000 | 1.000000 |
| 75% | 1369.000000 | 0.000000 | 62.800000 | 31.800000 | 662.000000 | 1200.000000 | 239.000000 | 95.000000 | 1.000000 |
| max | 1825.000000 | 1.000000 | 95.600000 | 100.000000 | 999.000000 | 20217.000000 | 8900.000000 | 100.000000 | 1.000000 |
#Get info
data.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 1825 entries, 0 to 1824 Data columns (total 19 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 id 1825 non-null int64 1 title 1825 non-null object 2 description 1825 non-null object 3 is_premium 1825 non-null int64 4 difficulty 1823 non-null object 5 solution_link 986 non-null object 6 acceptance_rate 1824 non-null float64 7 frequency 1824 non-null float64 8 url 1824 non-null object 9 discuss_count 1823 non-null float64 10 accepted 1825 non-null object 11 submissions 1824 non-null object 12 companies 1748 non-null object 13 related_topics 1571 non-null object 14 likes 1825 non-null int64 15 dislikes 1825 non-null int64 16 rating 1825 non-null int64 17 asked_by_faang 1825 non-null int64 18 similar_questions 745 non-null object dtypes: float64(3), int64(6), object(10) memory usage: 271.0+ KB
Plot the scatter plot of related topics and their average acceptance rates¶
# Set Plot Style
sns.set_style("darkgrid", {"axes.facecolor": "black", "grid.color": "#5b5b5b"})
# DataFrame to store related topics and their corresponding acceptance rates
# type conversion in datacleaning
data['related_topics'] = data['related_topics'].astype(str)
related_topics_acceptance = []
for index, row in data.iterrows():
topics = re.findall(r'\w+', row['related_topics'])
acceptance_rate = row['acceptance_rate']
for topic in topics:
related_topics_acceptance.append([topic, acceptance_rate])
related_topics_acceptance_df = pd.DataFrame(related_topics_acceptance, columns=['related_topic', 'acceptance_rate'])
# Average acceptance rate for each related topic
topic_acceptance_mean = related_topics_acceptance_df.groupby('related_topic').mean().reset_index()
# Plot the scatter plot of related topics and their average acceptance rates
plt.figure(figsize=(12,6))
sns.scatterplot(data=topic_acceptance_mean, x='related_topic', y='acceptance_rate', palette='dark', marker='o', color='orange',edgecolor='black')
plt.title('Average Acceptance Rate by Related Topic', fontsize=20)
plt.xlabel('Related Topic', fontsize=14)
plt.ylabel('Acceptance Rate', fontsize=14)
plt.xticks(rotation=90)
plt.savefig('related_topic_acceptance_rate.png', dpi=550,bbox_inches='tight')
plt.show()
Analyzing Difficulty Distribution using countplot¶
# Analyze difficulty distribution
plt.figure(figsize=(8, 6))
sns.countplot(data=data, x='difficulty', palette=['orange', '#fed271','#fee9bb'],width=0.5,edgecolor='black')
plt.title('Distribution of Difficulty Levels', fontsize=16)
plt.xlabel('Difficulty', fontsize=14)
plt.ylabel('Count', fontsize=14)
plt.savefig('difficulty_distribution.png', dpi=550 , bbox_inches='tight')
plt.show()
Analyzing acceptance rate distribution using histogram¶
# Analyze acceptance rate distribution
plt.figure(figsize=(8, 6))
sns.histplot(data=data,x='acceptance_rate',kde=True,color='orange',edgecolor='black') #kernel density estimation
plt.title('Distribution of Acceptance Rates', fontsize=16)
plt.xlabel('Acceptance Rate', fontsize=14)
plt.ylabel('Frequency', fontsize=14)
plt.savefig('acceptance_rate_distribution.png', dpi=550,bbox_inches='tight')
plt.show()
Analyzing the relationship between difficulty and acceptance rate using boxplot¶
# Analyze the relationship between difficulty and acceptance rate
plt.figure(figsize=(8, 6))
sns.boxplot(data=data, x='difficulty', y='acceptance_rate', palette=['orange', '#fed271','#fee9bb'])
plt.title('Acceptance Rate vs. Difficulty', fontsize=16)
plt.xlabel('Difficulty', fontsize=14)
plt.ylabel('Acceptance Rate', fontsize=14)
plt.savefig('acceptance_rate_vs_difficulty.png', dpi=550,bbox_inches='tight')
plt.show()
Analyzing premium vs non-premium problems using countplot¶
# Analyze premium vs non-premium problems
plt.figure(figsize=(8, 6))
sns.countplot(data=data, x='is_premium', palette=['orange', '#fed271'],edgecolor='black')
plt.title('Premium vs Non-Premium Problems', fontsize=16)
plt.xlabel('Premium Status', fontsize=14)
plt.ylabel('Count', fontsize=14)
plt.xticks(ticks=[0, 1], labels=['Non-Premium', 'Premium'])
plt.savefig('premium_vs_non_premium.png', dpi=550,bbox_inches='tight')
plt.show()
Analyzing the relationship between premium status and difficulty using countplot¶
# Analyze the relationship between premium status and difficulty
plt.figure(figsize=(8, 6))
sns.countplot(data=data, x='difficulty', hue='is_premium', palette=['orange', '#fed271'],edgecolor='black')
plt.title('Difficulty Distribution for Premium and Non-Premium Problems', fontsize=16)
plt.xlabel('Difficulty', fontsize=14)
plt.ylabel('Count', fontsize=14)
legend = plt.legend(title='Premium Status', title_fontsize=12, labels=['Non-Premium', 'Premium'],labelcolor='white')
legend.get_title().set_color('white')
plt.savefig('difficulty_distribution_premium_vs_non_premium.png',dpi=550,bbox_inches='tight')
plt.show()
Analyzing the relationship between premium status and acceptance rate using boxplot¶
# Analyze the relationship between premium status and acceptance rate
plt.figure(figsize=(8, 6))
sns.boxplot(data=data, x='is_premium', y='acceptance_rate',palette=['orange', '#fed271'])
plt.title('Acceptance Rate for Premium and Non-Premium Problems', fontsize=16)
plt.xlabel('Premium Status', fontsize=14)
plt.ylabel('Acceptance Rate', fontsize=14)
plt.xticks(ticks=[0, 1], labels=['Non-Premium', 'Premium']) #ticks[x axis,y axis]
plt.savefig('acceptance_rate_premium_vs_non_premium.png', dpi=550)
plt.show()
Generating a pairplot graph based on is_premium¶
#Pairplot for all the data where hue is premium
sns.pairplot(data=data,hue='is_premium',palette=['orange', '#fed271'])
plt.show()
Generating a pie chart on asked by FAANG or not using ply.pie¶
colors = ['orange', '#fed271']
plt.pie(data.asked_by_faang.value_counts(), labels=['Asked by faang', 'Not asked by faang'],explode = (0.2, 0), autopct='%.2f%%',colors=colors)
([<matplotlib.patches.Wedge at 0x1aaefdb4890>, <matplotlib.patches.Wedge at 0x1aaf30b6ed0>], [Text(-0.6660828443579865, 1.1163931406328036, 'Asked by faang'), Text(0.5636085606106042, -0.9446403497662182, 'Not asked by faang')], [Text(-0.4098971349895301, 0.6870111634663405, '67.12%'), Text(0.3074228512421477, -0.5152583725997554, '32.88%')])
Generating a bar chart displaying the top 20 companies based on question count using barlot¶
company_count = {}
data['companies']=data['companies'].astype(str)
for companies in data['companies']:
for company in re.findall(r'\w+', companies):
company_count[company] = company_count.get(company,0) + 1
# Create a DataFrame from the company count dictionary
company_data = pd.DataFrame.from_dict(company_count, orient='index', columns=['count']).reset_index()
company_data.columns = ['company', 'count']
# Sort companies by count and get the top 20
top_companies = company_data.sort_values(by='count', ascending=False).head(20)
# Plot the top 20 companies
plt.figure(figsize=(12, 6))
sns.barplot(data=top_companies, x='company', y='count', color='orange',edgecolor='black')
plt.title('Top 20 Companies Asking Problems', fontsize=16)
plt.xlabel('Company', fontsize=14)
plt.ylabel('Count', fontsize=14)
plt.xticks(rotation=90) # Rotate company names by 90 degrees
plt.savefig('top_companies.png', dpi=550)
plt.show()
Some other operations¶
#fetch the questions that were asked in salesforce
data_sales_force = data[data['companies'].str.contains('Salesforce')]
data_sales_force
| id | title | description | is_premium | difficulty | solution_link | acceptance_rate | frequency | url | discuss_count | accepted | submissions | companies | related_topics | likes | dislikes | rating | asked_by_faang | similar_questions | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 61 | 62 | Unique Paths | A robot is located at the top-left corner of a... | 0 | Medium | /articles/unique-paths | 56.3 | 50.8 | https://leetcode.com/problems/unique-paths | 999.0 | 621.6K | 1.1M | Microsoft,Amazon,Facebook,Google,Bloomberg,Qua... | Array,Dynamic Programming | 4856 | 240 | 95 | 1 | [Unique Paths II, /problems/unique-paths-ii/, ... |
| 150 | 151 | Reverse Words in a String | Given an input string `s`, reverse the order o... | 0 | Medium | /articles/reverse-words-in-a-string | 24.1 | 52.4 | https://leetcode.com/problems/reverse-words-in... | 999.0 | 516.5K | 2.1M | Microsoft,Oracle,LinkedIn,Apple,Salesforce | String | 1583 | 3206 | 33 | 1 | [Reverse Words in a String II, /problems/rever... |
| 294 | 295 | Find Median from Data Stream | The median is the middle value in an ordered i... | 0 | Hard | /articles/find-median-from-data-stream | 47.4 | 87.3 | https://leetcode.com/problems/find-median-from... | 881.0 | 288K | 607.7K | Amazon,Facebook,Microsoft,ByteDance,Google,App... | Heap,Design | 3979 | 74 | 98 | 1 | [Sliding Window Median, /problems/sliding-wind... |
| 459 | 460 | LFU Cache | Design and implement a data structure for a Le... | 0 | Hard | NaN | 36.4 | 81.8 | https://leetcode.com/problems/lfu-cache | 675.0 | 103.5K | 284.3K | Amazon,Microsoft,Google,Citadel,Bloomberg,Sale... | Design | 1935 | 150 | 93 | 1 | [LRU Cache, /problems/lru-cache/, Medium], [De... |
| 487 | 488 | Zuma Game | Think about Zuma Game. You have a row of balls... | 0 | Hard | NaN | 38.2 | 42.5 | https://leetcode.com/problems/zuma-game | 143.0 | 16.5K | 43.2K | Salesforce,Bloomberg | Depth-first Search | 277 | 301 | 48 | 0 | NaN |
| 494 | 495 | Teemo Attacking | In LOL world, there is a hero called Teemo and... | 0 | Medium | /articles/teemo-attacking | 56.1 | 5.8 | https://leetcode.com/problems/teemo-attacking | 663.0 | 73.7K | 131.3K | Salesforce | Array | 519 | 1041 | 33 | 0 | [Merge Intervals, /problems/merge-intervals/, ... |
| 677 | 678 | Valid Parenthesis String | Given a string `s` containing only three types... | 0 | Medium | /articles/valid-parenthesis-string | 31.7 | 39.3 | https://leetcode.com/problems/valid-parenthesi... | 665.0 | 131.5K | 414.2K | Salesforce,Facebook,Amazon,Uber,Oracle | String | 2319 | 65 | 97 | 1 | [Special Binary String, /problems/special-bina... |
| 738 | 739 | Daily Temperatures | Given a list of daily temperatures `T`, return... | 0 | Medium | /articles/daily-temperatures | 64.8 | 73.7 | https://leetcode.com/problems/daily-temperatures | 960.0 | 232K | 357.9K | Facebook,Bloomberg,Amazon,ByteDance,Google,Ado... | Hash Table,Stack | 4052 | 124 | 97 | 1 | [Next Greater Element I, /problems/next-greate... |
| 775 | 776 | Split BST | Given a Binary Search Tree (BST) with root nod... | 1 | Medium | /articles/split-bst | 56.7 | 15.8 | https://leetcode.com/problems/split-bst | 120.0 | 21.4K | 37.8K | Google,Salesforce | Tree,Recursion | 734 | 62 | 92 | 1 | [Delete Node in a BST, /problems/delete-node-i... |
| 919 | 920 | Number of Music Playlists | Your music player contains `N` different songs... | 0 | Hard | /articles/number-of-music-playlists | 48.0 | 35.4 | https://leetcode.com/problems/number-of-music-... | 74.0 | 14.2K | 29.6K | Salesforce,Facebook | Dynamic Programming | 542 | 56 | 91 | 1 | NaN |
| 1109 | 1110 | Delete Nodes And Return Forest | Given the `root` of a binary tree, each node i... | 0 | Medium | NaN | 67.9 | 31.3 | https://leetcode.com/problems/delete-nodes-and... | 819.0 | 96.5K | 142.2K | Google,Amazon,Facebook,Salesforce | Tree,Depth-first Search | 1747 | 54 | 97 | 1 | NaN |
| 1162 | 1163 | Last Substring in Lexicographical Order | Given a string `s`, return the last substring ... | 0 | Hard | NaN | 36.3 | 48.7 | https://leetcode.com/problems/last-substring-i... | 233.0 | 24.3K | 66.8K | Goldman Sachs,Salesforce | String,Suffix Array | 317 | 358 | 47 | 0 | NaN |
| 1282 | 1283 | Find the Smallest Divisor Given a Threshold | Given an array of integers `nums` and an integ... | 0 | Medium | /articles/find-the-smallest-divisor-given-a-th... | 49.9 | 44.9 | https://leetcode.com/problems/find-the-smalles... | 348.0 | 55.8K | 111.8K | Salesforce,Google | Binary Search | 716 | 128 | 85 | 1 | NaN |
| 1658 | 1659 | Maximize Grid Happiness | You are given four integers, `m`, `n`, `introv... | 0 | Hard | NaN | 35.6 | 24.3 | https://leetcode.com/problems/maximize-grid-ha... | 36.0 | 2.5K | 7.1K | Salesforce | Dynamic Programming,Backtracking | 128 | 42 | 75 | 0 | NaN |
| 1700 | 1701 | Average Waiting Time | There is a restaurant with a single chef. You ... | 0 | Medium | NaN | 61.3 | 2.5 | https://leetcode.com/problems/average-waiting-... | 229.0 | 10.8K | 17.7K | Salesforce | Array | 160 | 17 | 90 | 0 | NaN |
| 1717 | 1718 | Construct the Lexicographically Largest Valid ... | Given an integer `n`, find a sequence that sat... | 0 | Medium | NaN | 46.3 | 5.0 | https://leetcode.com/problems/construct-the-le... | 81.0 | 4.7K | 10.1K | Salesforce | Backtracking,Recursion | 198 | 14 | 93 | 0 | NaN |
#fetch the questions that were asked in amazon
data_amazon = data[data['companies'].str.contains('Amazon')]
data_amazon
| id | title | description | is_premium | difficulty | solution_link | acceptance_rate | frequency | url | discuss_count | accepted | submissions | companies | related_topics | likes | dislikes | rating | asked_by_faang | similar_questions | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | Two Sum | Given an array of integers `nums` and an integ... | 0 | Easy | /articles/two-sum | 46.7 | 100.0 | https://leetcode.com/problems/two-sum | 999.0 | 4.1M | 8.7M | Amazon,Google,Apple,Adobe,Microsoft,Bloomberg,... | Array,Hash Table | 20217 | 712 | 97 | 1 | [3Sum, /problems/3sum/, Medium], [4Sum, /probl... |
| 1 | 2 | Add Two Numbers | You are given two non-empty linked lists repre... | 0 | Medium | NaN | 35.7 | 93.1 | https://leetcode.com/problems/add-two-numbers | 999.0 | 1.9M | 5.2M | Bloomberg,Microsoft,Amazon,Google,Facebook,App... | Linked List,Math,Recursion | 11350 | 2704 | 81 | 1 | [Multiply Strings, /problems/multiply-strings/... |
| 3 | 4 | Median of Two Sorted Arrays | Given two sorted arrays `nums1` and `nums2` of... | 0 | Hard | /articles/median-of-two-sorted-arrays | 31.4 | NaN | https://leetcode.com/problems/median-of-two-so... | 999.0 | 904.7K | 2.9M | Amazon,Goldman Sachs,Facebook,Microsoft,Apple,... | Array,Binary Search,Divide and Conquer | 9665 | 1486 | 87 | 1 | NaN |
| 4 | 5 | Longest Palindromic Substring | Given a string `s`, return the longest palindr... | 0 | Medium | /articles/longest-palindromic-substring | 30.6 | 84.7 | https://leetcode.com/problems/longest-palindro... | NaN | 1.3M | NaN | Amazon,Microsoft,Wayfair,Facebook,Adobe,eBay,G... | String,Dynamic Programming | 10271 | 670 | 94 | 1 | [Shortest Palindrome, /problems/shortest-palin... |
| 6 | 7 | Reverse Integer | Given a signed 32-bit integer `x`, return `x` ... | 0 | Easy | /articles/reverse-integer | 25.9 | 80.9 | NaN | 999.0 | 1.5M | 5.7M | Amazon,Google,Apple,Facebook,Bloomberg,America... | Math | 4548 | 6971 | 39 | 1 | [String to Integer (atoi), /problems/string-to... |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 1791 | 1792 | Maximum Average Pass Ratio | There is a school that has classes of students... | 0 | Medium | NaN | 56.3 | 0.3 | https://leetcode.com/problems/maximum-average-... | 161.0 | 9K | 15.9K | Amazon | Heap | 242 | 39 | 86 | 1 | NaN |
| 1794 | 1795 | Rearrange Products Table | SQL Schema | 1 | Easy | NaN | 90.6 | 0.0 | https://leetcode.com/problems/rearrange-produc... | 28.0 | 1.7K | 1.9K | Amazon | nan | 14 | 0 | 100 | 1 | NaN |
| 1798 | 1799 | Maximize Score After N Operations | You are given `nums`, an array of positive int... | 0 | Hard | NaN | 50.4 | 4.7 | https://leetcode.com/problems/maximize-score-a... | 68.0 | 4K | 7.8K | Amazon | Dynamic Programming,Backtracking,Recursion | 127 | 7 | 95 | 1 | NaN |
| 1808 | 1809 | Ad-Free Sessions | SQL Schema | 1 | Easy | NaN | 71.5 | 0.0 | https://leetcode.com/problems/ad-free-sessions | 33.0 | 1K | 1.4K | Amazon | nan | 11 | 3 | 79 | 1 | NaN |
| 1810 | 1811 | Find Interview Candidates | SQL Schema | 1 | Medium | NaN | 73.2 | 0.0 | https://leetcode.com/problems/find-interview-c... | 35.0 | 460 | 631 | Amazon | nan | 16 | 1 | 94 | 1 | NaN |
689 rows × 19 columns
#fetch the questions that were asked in amazon as well as salesforce
data_amazon_salesforce = data[data['companies'].str.contains('Amazon') & data['companies'].str.contains('Salesforce') ]
data_amazon_salesforce
| id | title | description | is_premium | difficulty | solution_link | acceptance_rate | frequency | url | discuss_count | accepted | submissions | companies | related_topics | likes | dislikes | rating | asked_by_faang | similar_questions | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 61 | 62 | Unique Paths | A robot is located at the top-left corner of a... | 0 | Medium | /articles/unique-paths | 56.3 | 50.8 | https://leetcode.com/problems/unique-paths | 999.0 | 621.6K | 1.1M | Microsoft,Amazon,Facebook,Google,Bloomberg,Qua... | Array,Dynamic Programming | 4856 | 240 | 95 | 1 | [Unique Paths II, /problems/unique-paths-ii/, ... |
| 294 | 295 | Find Median from Data Stream | The median is the middle value in an ordered i... | 0 | Hard | /articles/find-median-from-data-stream | 47.4 | 87.3 | https://leetcode.com/problems/find-median-from... | 881.0 | 288K | 607.7K | Amazon,Facebook,Microsoft,ByteDance,Google,App... | Heap,Design | 3979 | 74 | 98 | 1 | [Sliding Window Median, /problems/sliding-wind... |
| 459 | 460 | LFU Cache | Design and implement a data structure for a Le... | 0 | Hard | NaN | 36.4 | 81.8 | https://leetcode.com/problems/lfu-cache | 675.0 | 103.5K | 284.3K | Amazon,Microsoft,Google,Citadel,Bloomberg,Sale... | Design | 1935 | 150 | 93 | 1 | [LRU Cache, /problems/lru-cache/, Medium], [De... |
| 677 | 678 | Valid Parenthesis String | Given a string `s` containing only three types... | 0 | Medium | /articles/valid-parenthesis-string | 31.7 | 39.3 | https://leetcode.com/problems/valid-parenthesi... | 665.0 | 131.5K | 414.2K | Salesforce,Facebook,Amazon,Uber,Oracle | String | 2319 | 65 | 97 | 1 | [Special Binary String, /problems/special-bina... |
| 738 | 739 | Daily Temperatures | Given a list of daily temperatures `T`, return... | 0 | Medium | /articles/daily-temperatures | 64.8 | 73.7 | https://leetcode.com/problems/daily-temperatures | 960.0 | 232K | 357.9K | Facebook,Bloomberg,Amazon,ByteDance,Google,Ado... | Hash Table,Stack | 4052 | 124 | 97 | 1 | [Next Greater Element I, /problems/next-greate... |
| 1109 | 1110 | Delete Nodes And Return Forest | Given the `root` of a binary tree, each node i... | 0 | Medium | NaN | 67.9 | 31.3 | https://leetcode.com/problems/delete-nodes-and... | 819.0 | 96.5K | 142.2K | Google,Amazon,Facebook,Salesforce | Tree,Depth-first Search | 1747 | 54 | 97 | 1 | NaN |
