Skip to content

Commit 67eb5e0

Browse files
authored
Merge pull request #568 from Abhay182005dat/main
Added solutions for the LC problems from 2880-2882
2 parents 0731108 + 21420fa commit 67eb5e0

File tree

4 files changed

+275
-0
lines changed

4 files changed

+275
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
id : 2880-select-data
3+
title : Select Data from a DataFrame
4+
sidebar_label: 2880 Select Data Leetcode
5+
tags:
6+
- LeetCode
7+
- Python
8+
- Data Science
9+
description: "This is a solution to the Select Data question from the Leetcode 2880 question"
10+
---
11+
12+
## Problem Description
13+
14+
Write a solution to select the name and age of the student with student_id = 101.
15+
16+
##Examples
17+
18+
Example 1:
19+
20+
Input:
21+
+------------+---------+-----+
22+
| student_id | name | age |
23+
+------------+---------+-----+
24+
| 101 | Ulysses | 13 |
25+
| 53 | William | 10 |
26+
| 128 | Henry | 6 |
27+
| 3 | Henry | 11 |
28+
+------------+---------+-----+
29+
30+
Output:
31+
+---------+-----+
32+
| name | age |
33+
+---------+-----+
34+
| Ulysses | 13 |
35+
+---------+-----+
36+
37+
##Intuition
38+
I will say as this is a Data Science Problem the solution is also straightforward . Hope it helps :)
39+
.
40+
41+
### Solution Code
42+
<Tabs>
43+
<TabItem value="Python" label="" default>
44+
<SolutionAuthor name="@Abhay:)"/>
45+
```Python
46+
import pandas as pd
47+
48+
def selectData(students: pd.DataFrame) -> pd.DataFrame:
49+
return students.loc[students['student_id'] == 101, ["name", "age"]]
50+
```
51+
</TabItem>
52+
</Tabs>
53+
## References
54+
- **Leetcode Problem :** [Select Data](https://leetcode.com/problems/select-data/)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
id : Create-a-New-Column
3+
title : Create a New column
4+
sidebar_label: 2881 Create a new column Leetcode
5+
tags:
6+
- LeetCode
7+
- Python
8+
- Data Science
9+
description: "This is a solution for the leetcode 2881 problem which is to create a new column.This problem uses pandas which is a python library for solving"
10+
---
11+
12+
## Problem Description
13+
14+
A company plans to provide its employees with a bonus.
15+
Write a solution to create a new column name bonus that contains the doubled values of the salary column.
16+
17+
##Examples
18+
19+
Input:
20+
DataFrame employees
21+
+---------+--------+
22+
| name | salary |
23+
+---------+--------+
24+
| Piper | 4548 |
25+
| Grace | 28150 |
26+
| Georgia | 1103 |
27+
| Willow | 6593 |
28+
| Finn | 74576 |
29+
| Thomas | 24433 |
30+
+---------+--------+
31+
Output:
32+
+---------+--------+--------+
33+
| name | salary | bonus |
34+
+---------+--------+--------+
35+
| Piper | 4548 | 9096 |
36+
| Grace | 28150 | 56300 |
37+
| Georgia | 1103 | 2206 |
38+
| Willow | 6593 | 13186 |
39+
| Finn | 74576 | 149152 |
40+
| Thomas | 24433 | 48866 |
41+
+---------+--------+--------+
42+
Explanation:
43+
A new column bonus is created by doubling the value in the column salary.
44+
45+
##Intuition
46+
I will say as this is a Data Science Problem the solution is also straightforward . Hope it helps :)
47+
.
48+
49+
### Solution Code
50+
<Tabs>
51+
<TabItem value="Python" label="" default>
52+
<SolutionAuthor name="@Abhay:)"/>
53+
```Python
54+
import pandas as pd
55+
56+
def createBonusColumn(employees: pd.DataFrame) -> pd.DataFrame:
57+
employees['bonus'] = employees['salary']*2
58+
return employees
59+
```
60+
</TabItem>
61+
</Tabs>
62+
## References
63+
- **Leetcode Problem :** [Create a new column](https://leetcode.com/problems/create-a-new-column/)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
id : Drop-Duplicate-Rows
3+
title : Drop Duplicate Rows
4+
sidebar_label: 2882 Drop Duplicate Rows
5+
tags:
6+
- LeetCode
7+
- Python
8+
- Data Science
9+
description: "This is a solution for the Leetcode problem 2882 which asks to drop duplicate rows and keep only the first occurence.
10+
This Problem is solved with the help of python library Pandas. "
11+
---
12+
13+
## Problem Description
14+
15+
There are some duplicate rows in the DataFrame based on the email column.
16+
Write a solution to remove these duplicate rows and keep only the first occurrence.
17+
The result format is in the following example.
18+
19+
##Examples
20+
21+
Example 1:
22+
Input:
23+
+-------------+---------+---------------------+
24+
| customer_id | name | email |
25+
+-------------+---------+---------------------+
26+
| 1 | Ella | emily@example.com |
27+
| 2 | David | michael@example.com |
28+
| 3 | Zachary | sarah@example.com |
29+
| 4 | Alice | john@example.com |
30+
| 5 | Finn | john@example.com |
31+
| 6 | Violet | alice@example.com |
32+
+-------------+---------+---------------------+
33+
Output:
34+
+-------------+---------+---------------------+
35+
| customer_id | name | email |
36+
+-------------+---------+---------------------+
37+
| 1 | Ella | emily@example.com |
38+
| 2 | David | michael@example.com |
39+
| 3 | Zachary | sarah@example.com |
40+
| 4 | Alice | john@example.com |
41+
| 6 | Violet | alice@example.com |
42+
+-------------+---------+---------------------+
43+
Explanation:
44+
Alic (customer_id = 4) and Finn (customer_id = 5) both use john@example.com, so only the first occurrence of this email is retained.
45+
46+
##Intuition
47+
I will say as this is a Data Science Problem the solution is also straightforward . Hope it helps :)
48+
.
49+
50+
### Solution Code
51+
<Tabs>
52+
<TabItem value="Python" label="" default>
53+
<SolutionAuthor name="@Abhay:)"/>
54+
```Python
55+
import pandas as pd
56+
57+
def dropDuplicateEmails(customers: pd.DataFrame) -> pd.DataFrame:
58+
customers.drop_duplicates(subset='email',keep='first',inplace = True)
59+
return customers
60+
```
61+
</TabItem>
62+
</Tabs>
63+
64+
## References
65+
- **Leetcode Problem :** [Drop Duplicate Rows](https://leetcode.com/problems/drop-duplicate-rows/description/)
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
id: Flexbox
3+
title: Flexbox
4+
sidebar_label: Flexbox
5+
sidebar_position: 2
6+
tags: [html, CSS, Flexbox]
7+
---
8+
9+
# Flexbox Layout in CSS
10+
11+
Flexbox, short for Flexible Box, is a layout model in CSS that allows you to design complex layouts more efficiently and with less code compared
12+
to traditional methods like floats or positioning.
13+
14+
## Introduction to Flexbox
15+
16+
Flexbox introduces a new way to layout, align, and distribute space among items in a container, even when their size is unknown or dynamic.
17+
It's particularly useful for creating responsive designs and aligning elements within a container in numerous ways.
18+
19+
## Basic Concepts
20+
21+
Flexbox revolves around two main components: the flex container and flex items.
22+
23+
### Flex Container
24+
25+
The parent element that holds flex items is called the flex container. To create a flex container, you set the CSS `display` property to `flex` or `inline-flex`.
26+
27+
```css
28+
.container {
29+
display: flex;
30+
}
31+
```
32+
---
33+
## Flex Items
34+
The children of a flex container are called flex items. These items can dynamically adjust their width, height, and orderto fill theavailable space within the
35+
flex container.
36+
37+
```html
38+
<div class="container">
39+
<div class="item">Item 1</div>
40+
<div class="item">Item 2</div>
41+
<div class="item">Item 3</div>
42+
</div>
43+
```
44+
## Main Axis and Cross Axis
45+
Flexbox operates along two axes: the main axis and the cross axis. The main axis is defined by the flex-direction property and determines the
46+
direction in which flex items are laid out, while the cross axis is perpendicular to it.
47+
48+
## Properties
49+
Flexbox provides several properties to control the layout and behavior of flex containers and items.
50+
51+
## Common Flex Container Properties
52+
'display': Specifies the type of box used for a flex container.
53+
'flex-direction': Establishes the main axis direction.
54+
'justify-content': Aligns flex items along the main axis.
55+
'align-items': Aligns flex items along the cross axis.
56+
'flex-wrap': Specifies whether flex items should wrap or not.
57+
58+
## Common Flex Item Properties
59+
'order': Specifies the order of a flex item relative to other flex items.
60+
'flex-grow': Specifies how a flex item grows relative to other flex items.
61+
'flex-shrink': Specifies how a flex item shrinks relative to other flex items.
62+
'flex-basis': Specifies the initial size of a flex item.
63+
'align-self': Allows the default alignment to be overridden for individual flex items.
64+
---
65+
```html
66+
<!DOCTYPE html>
67+
<html>
68+
<head>
69+
<title>Flexbox Example</title>
70+
<style>
71+
.container {
72+
display: flex;
73+
justify-content: space-between;
74+
align-items: center;
75+
}
76+
.item {
77+
flex: 1;
78+
padding: 10px;
79+
text-align: center;
80+
}
81+
</style>
82+
</head>
83+
<body>
84+
<div class="container">
85+
<div class="item" style="background-color: #FF5733;">Item 1</div>
86+
<div class="item" style="background-color: #33FF99;">Item 2</div>
87+
<div class="item" style="background-color: #3366FF;">Item 3</div>
88+
</div>
89+
</body>
90+
</html>
91+
```
92+
## Conclusion
93+
Flexbox simplifies the process of creating layouts that adapt to different screen sizes and devices. By mastering Flexbox, you can create more responsive and dynamic web designs with less effort.

0 commit comments

Comments
 (0)