Skip to content

Commit 9bc5e26

Browse files
committed
Added task 3374
1 parent 0733051 commit 9bc5e26

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,6 +2133,7 @@
21332133
| 3377 |[Digit Operations to Make Two Integers Equal](src/main/kotlin/g3301_3400/s3377_digit_operations_to_make_two_integers_equal)| Medium | Math, Heap_Priority_Queue, Graph, Shortest_Path, Number_Theory | 215 | 100.00
21342134
| 3376 |[Minimum Time to Break Locks I](src/main/kotlin/g3301_3400/s3376_minimum_time_to_break_locks_i)| Medium | Array, Dynamic_Programming, Bit_Manipulation, Backtracking, Bitmask | 202 | 100.00
21352135
| 3375 |[Minimum Operations to Make Array Values Equal to K](src/main/kotlin/g3301_3400/s3375_minimum_operations_to_make_array_values_equal_to_k)| Easy | Array, Hash_Table | 191 | 100.00
2136+
| 3374 |[First Letter Capitalization II](src/main/kotlin/g3301_3400/s3374_first_letter_capitalization_ii)| Hard | Database | 261 | 84.21
21362137
| 3373 |[Maximize the Number of Target Nodes After Connecting Trees II](src/main/kotlin/g3301_3400/s3373_maximize_the_number_of_target_nodes_after_connecting_trees_ii)| Hard | Depth_First_Search, Breadth_First_Search, Tree | 26 | 98.75
21372138
| 3372 |[Maximize the Number of Target Nodes After Connecting Trees I](src/main/kotlin/g3301_3400/s3372_maximize_the_number_of_target_nodes_after_connecting_trees_i)| Medium | Depth_First_Search, Breadth_First_Search, Tree | 50 | 99.49
21382139
| 3371 |[Identify the Largest Outlier in an Array](src/main/kotlin/g3301_3400/s3371_identify_the_largest_outlier_in_an_array)| Medium | Array, Hash_Table, Counting, Enumeration | 5 | 100.00
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
2+
[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
3+
4+
## 3374\. First Letter Capitalization II
5+
6+
Hard
7+
8+
SQL Schema
9+
10+
Table: `user_content`
11+
12+
+-------------+---------+
13+
| Column Name | Type |
14+
+-------------+---------+
15+
| content_id | int |
16+
| content_text| varchar |
17+
+-------------+---------+
18+
content_id is the unique key for this table. Each row contains a unique ID and the corresponding text content.
19+
20+
Write a solution to transform the text in the `content_text` column by applying the following rules:
21+
22+
* Convert the **first letter** of each word to **uppercase** and the **remaining** letters to **lowercase**
23+
* Special handling for words containing special characters:
24+
* For words connected with a hyphen `-`, **both parts** should be **capitalized** (**e.g.**, top-rated → Top-Rated)
25+
* All other **formatting** and **spacing** should remain **unchanged**
26+
27+
Return _the result table that includes both the original `content_text` and the modified text following the above rules_.
28+
29+
The result format is in the following example.
30+
31+
**Example:**
32+
33+
**Input:**
34+
35+
user\_content table:
36+
37+
+------------+---------------------------------+
38+
| content_id | content_text |
39+
+------------+---------------------------------+
40+
| 1 | hello world of SQL |
41+
| 2 | the QUICK-brown fox |
42+
| 3 | modern-day DATA science |
43+
| 4 | web-based FRONT-end development |
44+
+------------+---------------------------------+
45+
46+
**Output:**
47+
48+
+------------+---------------------------------+---------------------------------+
49+
| content_id | original_text | converted_text |
50+
+------------+---------------------------------+---------------------------------+
51+
| 1 | hello world of SQL | Hello World Of Sql |
52+
| 2 | the QUICK-brown fox | The Quick-Brown Fox |
53+
| 3 | modern-day DATA science | Modern-Day Data Science |
54+
| 4 | web-based FRONT-end development | Web-Based Front-End Development |
55+
+------------+---------------------------------+---------------------------------+
56+
57+
**Explanation:**
58+
59+
* For content\_id = 1:
60+
* Each word's first letter is capitalized: "Hello World Of Sql"
61+
* For content\_id = 2:
62+
* Contains the hyphenated word "QUICK-brown" which becomes "Quick-Brown"
63+
* Other words follow normal capitalization rules
64+
* For content\_id = 3:
65+
* Hyphenated word "modern-day" becomes "Modern-Day"
66+
* "DATA" is converted to "Data"
67+
* For content\_id = 4:
68+
* Contains two hyphenated words: "web-based" → "Web-Based"
69+
* And "FRONT-end" → "Front-End"
70+
71+
## Solution
72+
73+
```python
74+
import pandas as pd
75+
76+
def capitalize_content(user_content):
77+
user_content['converted_text'] = (user_content.content_text.apply(lambda x: x.title()))
78+
return user_content.rename(columns={'content_text': 'original_text'})
79+
```

0 commit comments

Comments
 (0)