mirror of
https://github.com/krishnadey30/LeetCode-Questions-CompanyWise.git
synced 2025-12-28 05:34:42 +00:00
## Description
- Add headers to all the CSV files
## Script used
```py
import csv
import os
# Set the path of the folder containing the CSV files
folder_path = "./LeetCode-Questions-CompanyWise"
headers = [
"ID",
"Title",
"Acceptance",
"Difficulty",
"Frequency",
"Leetcode Question Link",
]
# Loop through all the CSV files in the folder
for file_name in os.listdir(folder_path):
if file_name.endswith(".csv"):
# Read the CSV file into a list of rows
file_path = os.path.join(folder_path, file_name)
with open(file_path, "r") as f:
reader = csv.reader(f)
rows = list(reader)
has_headers = False
if len(rows) > 0 and rows[0] == headers:
has_headers = True
if not has_headers:
rows.insert(0, headers)
# Write the list of rows back to the CSV file
with open(file_path, "w", newline="") as f:
writer = csv.writer(f)
writer.writerows(rows)
```
1.3 KiB
1.3 KiB
| 1 | ID | Title | Acceptance | Difficulty | Frequency | Leetcode Question Link |
|---|---|---|---|---|---|---|
| 2 | 593 | Valid Square | 43.1% | Medium | 2.012428334541107 | https://leetcode.com/problems/valid-square |
| 3 | 647 | Palindromic Substrings | 60.6% | Medium | 1.4078595470997393 | https://leetcode.com/problems/palindromic-substrings |
| 4 | 730 | Count Different Palindromic Subsequences | 41.8% | Hard | 0.8032907596583713 | https://leetcode.com/problems/count-different-palindromic-subsequences |
| 5 | 203 | Remove Linked List Elements | 38.6% | Easy | 0.5359603141290598 | https://leetcode.com/problems/remove-linked-list-elements |
| 6 | 202 | Happy Number | 50.4% | Easy | 0.07100316365622945 | https://leetcode.com/problems/happy-number |
| 7 | 75 | Sort Colors | 47.3% | Medium | 0.05709845281459711 | https://leetcode.com/problems/sort-colors |
| 8 | 716 | Max Stack | 42.6% | Easy | 0.04103139667786253 | https://leetcode.com/problems/max-stack |
| 9 | 380 | Insert Delete GetRandom O(1) | 47.5% | Medium | 0.020896975877216107 | https://leetcode.com/problems/insert-delete-getrandom-o1 |
| 10 | 5 | Longest Palindromic Substring | 29.5% | Medium | 0.019425420619316486 | https://leetcode.com/problems/longest-palindromic-substring |
| 11 | 155 | Min Stack | 44.5% | Easy | 0.010200700488022775 | https://leetcode.com/problems/min-stack |
| 12 | 167 | Two Sum II - Input array is sorted | 54.1% | Easy | 0.005280540323033287 | https://leetcode.com/problems/two-sum-ii-input-array-is-sorted |
| 13 | 1206 | Design Skiplist | 57.3% | Hard | 0 | https://leetcode.com/problems/design-skiplist |