# bitsbybhargav/leetcode architecture

> Architecture diagram of the GitHub repository bitsbybhargav/leetcode, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bitsbybhargav/leetcode
- Repository: https://github.com/bitsbybhargav/leetcode

## Overview

1. This repository is a LeetCode SQL solutions collection, not an application with a runtime service. Each top-level folder corresponds to one database problem and is intended to be solved independently.

2. The main architectural unit is the problem directory. For example, `175-combine-two-tables/`, `176-second-highest-salary/`, and `184-department-highest-salary/` each contain a problem-specific `README.md` and a single `.sql` solution file.

3. The root `README.md` is minimal and only labels the repository as “LeetCode,” so there is no central product documentation, shared design, or orchestration layer.

4. There is no shared library code, common schema module, or cross-folder dependency graph. Each SQL file stands alone and targets the schema described by its own LeetCode prompt.

5. The primary data flow in every module is:
   input tables defined by the challenge -> SQL query or DML statement -> result set or updated table expected by LeetCode.
   There is no persistent application state beyond the database tables used in each exercise.

6. The repository includes both read-only analytics queries and data modification queries. Examples include selection/reporting problems like `1174-sales-analysis-iii.sql` and mutation-oriented problems like `196-delete-duplicate-emails.sql` and `627-swap-sex-of-employees.sql`.

7. The problem set spans common SQL patterns and relational boundaries: joins, grouping, ranking, deduplication, subqueries, window-like logic, and conditional filtering. Many files encode one focused query strategy per problem rather than a multi-step pipeline.

8. Directory names are prefixed with the LeetCode problem ID, which makes the structure stable and easy to map back to the original prompt. This also suggests the intended architecture for navigation is by problem number, not by feature area.

9. The `README.md` inside each problem folder likely mirrors the problem statement and acts as local context for the corresponding SQL file. In architectural terms, the README is documentation boundary, while the `.sql` file is the implementation boundary.

10. There is no visible build system, test harness, package manager, container setup, or deployment infrastructure in this repository snapshot. The execution environment is effectively the LeetCode SQL engine or any compatible SQL dialect used to validate the solution.

11. Because the repository is a set of independent exercises, the best diagram is a hub-and-spoke or flat catalog view: one root repository containing many isolated problem modules, each with documentation and a single query artifact.

12. If you are drawing the architecture, the key labels should be “problem specification,” “SQL solution,” and “database tables/result set,” with no downstream services, API layer, or shared backend components.

Main entry points: [`175-combine-two-tables/combine-two-tables.sql`](https://github.com/bitsbybhargav/leetcode/blob/main/175-combine-two-tables/combine-two-tables.sql) (Combine tables), [`184-department-highest-salary/department-highest-salary.sql`](https://github.com/bitsbybhargav/leetcode/blob/main/184-department-highest-salary/department-highest-salary.sql) (Dept top salary), [`185-department-top-three-salaries/department-top-three-salaries.sql`](https://github.com/bitsbybhargav/leetcode/blob/main/185-department-top-three-salaries/department-top-three-salaries.sql) (Dept top three), [`196-delete-duplicate-emails/delete-duplicate-emails.sql`](https://github.com/bitsbybhargav/leetcode/blob/main/196-delete-duplicate-emails/delete-duplicate-emails.sql) (Delete duplicates)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_repo["Repository"]
  node_root_readme["LeetCode<br/>root docs<br/>[README.md]"]
  node_problem_catalog["Problem catalog<br/>module catalog"]
  node_problem_spec["Problem spec<br/>local prompt"]
  node_sql_solution["SQL solution<br/>query artifact"]
  node_db_io[("Tables / result<br/>sql io")]
end

subgraph group_problems["Problem modules"]
  node_p175_readme["Combine tables<br/>problem spec<br/>[README.md]"]
  node_p175_sql["Combine tables<br/>solution sql"]
  node_p184_readme["Dept top salary<br/>problem spec<br/>[README.md]"]
  node_p184_sql["Dept top salary<br/>solution sql"]
  node_p185_readme["Dept top three<br/>problem spec<br/>[README.md]"]
  node_p185_sql["Dept top three<br/>solution sql"]
  node_p196_readme["Delete duplicates<br/>problem spec<br/>[README.md]"]
  node_p196_sql["Delete duplicates<br/>solution sql"]
  node_p197_readme["Rising temperature<br/>problem spec<br/>[README.md]"]
  node_p197_sql["Rising temperature<br/>solution sql"]
  node_p570_readme["Direct reports<br/>problem spec<br/>[README.md]"]
  node_p570_sql["Direct reports<br/>solution sql"]
  node_p607_readme["Sales person<br/>problem spec<br/>[README.md]"]
  node_p607_sql["Sales person<br/>solution sql<br/>[sales-person.sql]"]
  node_p620_readme["Not boring<br/>problem spec<br/>[README.md]"]
  node_p620_sql["Not boring<br/>solution sql"]
  node_p627_readme["Swap sex<br/>problem spec<br/>[README.md]"]
  node_p627_sql["Swap sex<br/>solution sql"]
end

node_root_readme -->|"describes"| node_problem_catalog
node_problem_catalog -->|"organizes"| node_problem_spec
node_problem_spec -->|"guides"| node_sql_solution
node_sql_solution -->|"reads/writes"| node_db_io
node_p175_readme -->|"specifies"| node_p175_sql
node_p175_sql -->|"joins"| node_db_io
node_p184_readme -->|"specifies"| node_p184_sql
node_p184_sql -->|"ranks"| node_db_io
node_p185_readme -->|"specifies"| node_p185_sql
node_p185_sql -->|"ranks"| node_db_io
node_p196_readme -->|"specifies"| node_p196_sql
node_p196_sql -->|"mutates"| node_db_io
node_p197_readme -->|"specifies"| node_p197_sql
node_p197_sql -->|"filters"| node_db_io
node_p570_readme -->|"specifies"| node_p570_sql
node_p570_sql -->|"aggregates"| node_db_io
node_p607_readme -->|"specifies"| node_p607_sql
node_p607_sql -->|"excludes"| node_db_io
node_p620_readme -->|"specifies"| node_p620_sql
node_p620_sql -->|"filters"| node_db_io
node_p627_readme -->|"specifies"| node_p627_sql
node_p627_sql -->|"mutates"| node_db_io

click node_root_readme "https://github.com/bitsbybhargav/leetcode/blob/main/README.md"
click node_p175_readme "https://github.com/bitsbybhargav/leetcode/blob/main/175-combine-two-tables/README.md"
click node_p175_sql "https://github.com/bitsbybhargav/leetcode/blob/main/175-combine-two-tables/combine-two-tables.sql"
click node_p184_readme "https://github.com/bitsbybhargav/leetcode/blob/main/184-department-highest-salary/README.md"
click node_p184_sql "https://github.com/bitsbybhargav/leetcode/blob/main/184-department-highest-salary/department-highest-salary.sql"
click node_p185_readme "https://github.com/bitsbybhargav/leetcode/blob/main/185-department-top-three-salaries/README.md"
click node_p185_sql "https://github.com/bitsbybhargav/leetcode/blob/main/185-department-top-three-salaries/department-top-three-salaries.sql"
click node_p196_readme "https://github.com/bitsbybhargav/leetcode/blob/main/196-delete-duplicate-emails/README.md"
click node_p196_sql "https://github.com/bitsbybhargav/leetcode/blob/main/196-delete-duplicate-emails/delete-duplicate-emails.sql"
click node_p197_readme "https://github.com/bitsbybhargav/leetcode/blob/main/197-rising-temperature/README.md"
click node_p197_sql "https://github.com/bitsbybhargav/leetcode/blob/main/197-rising-temperature/rising-temperature.sql"
click node_p570_readme "https://github.com/bitsbybhargav/leetcode/blob/main/570-managers-with-at-least-5-direct-reports/README.md"
click node_p570_sql "https://github.com/bitsbybhargav/leetcode/blob/main/570-managers-with-at-least-5-direct-reports/managers-with-at-least-5-direct-reports.sql"
click node_p607_readme "https://github.com/bitsbybhargav/leetcode/blob/main/607-sales-person/README.md"
click node_p607_sql "https://github.com/bitsbybhargav/leetcode/blob/main/607-sales-person/sales-person.sql"
click node_p620_readme "https://github.com/bitsbybhargav/leetcode/blob/main/620-not-boring-movies/README.md"
click node_p620_sql "https://github.com/bitsbybhargav/leetcode/blob/main/620-not-boring-movies/not-boring-movies.sql"
click node_p627_readme "https://github.com/bitsbybhargav/leetcode/blob/main/627-swap-sex-of-employees/README.md"
click node_p627_sql "https://github.com/bitsbybhargav/leetcode/blob/main/627-swap-sex-of-employees/swap-sex-of-employees.sql"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_root_readme,node_problem_catalog,node_problem_spec,node_sql_solution,node_db_io toneBlue
class node_p175_readme,node_p175_sql,node_p184_readme,node_p184_sql,node_p185_readme,node_p185_sql,node_p196_readme,node_p196_sql,node_p197_readme,node_p197_sql,node_p570_readme,node_p570_sql,node_p607_readme,node_p607_sql,node_p620_readme,node_p620_sql,node_p627_readme,node_p627_sql toneAmber
```

## Components

### Repository

Top-level LeetCode SQL catalog.

- [LeetCode](https://github.com/bitsbybhargav/leetcode/blob/main/README.md): root docs · Minimal repository README. · `README.md`
- **Problem catalog**: module catalog · Flat set of numbered SQL exercises.
- **Problem spec**: local prompt · Per-problem README describing the challenge and schema.
- **SQL solution**: query artifact · Standalone SQL file implementing the answer for a single problem.
- **Tables / result**: sql io · Input tables from the prompt and the expected result set or update.

### Problem modules

Independent LeetCode exercises, each with local spec and one solution file.

- [Combine tables](https://github.com/bitsbybhargav/leetcode/blob/main/175-combine-two-tables/README.md): problem spec · Find employees enriched with department/company data. · `175-combine-two-tables/README.md`
- [Combine tables](https://github.com/bitsbybhargav/leetcode/blob/main/175-combine-two-tables/combine-two-tables.sql): solution sql · Join-based query for the two tables exercise. · `175-combine-two-tables/combine-two-tables.sql`
- [Dept top salary](https://github.com/bitsbybhargav/leetcode/blob/main/184-department-highest-salary/README.md): problem spec · Return the highest-paid employee per department. · `184-department-highest-salary/README.md`
- [Dept top salary](https://github.com/bitsbybhargav/leetcode/blob/main/184-department-highest-salary/department-highest-salary.sql): solution sql · Ranking/join query for department-level maxima. · `184-department-highest-salary/department-highest-salary.sql`
- [Dept top three](https://github.com/bitsbybhargav/leetcode/blob/main/185-department-top-three-salaries/README.md): problem spec · Return the top three salaries per department. · `185-department-top-three-salaries/README.md`
- [Dept top three](https://github.com/bitsbybhargav/leetcode/blob/main/185-department-top-three-salaries/department-top-three-salaries.sql): solution sql · Per-group ranking query with salary cutoff logic. · `185-department-top-three-salaries/department-top-three-salaries.sql`
- [Delete duplicates](https://github.com/bitsbybhargav/leetcode/blob/main/196-delete-duplicate-emails/README.md): problem spec · Remove duplicate emails while keeping one row. · `196-delete-duplicate-emails/README.md`
- [Delete duplicates](https://github.com/bitsbybhargav/leetcode/blob/main/196-delete-duplicate-emails/delete-duplicate-emails.sql): solution sql · Mutation-oriented statement for deduplication. · `196-delete-duplicate-emails/delete-duplicate-emails.sql`
- [Rising temperature](https://github.com/bitsbybhargav/leetcode/blob/main/197-rising-temperature/README.md): problem spec · Find days with a higher temperature than the previous day. · `197-rising-temperature/README.md`
- [Rising temperature](https://github.com/bitsbybhargav/leetcode/blob/main/197-rising-temperature/rising-temperature.sql): solution sql · Self-join or date-difference query over weather rows. · `197-rising-temperature/rising-temperature.sql`
- [Direct reports](https://github.com/bitsbybhargav/leetcode/blob/main/570-managers-with-at-least-5-direct-reports/README.md): problem spec · Identify managers with at least five reports. · `570-managers-with-at-least-5-direct-reports/README.md`
- [Direct reports](https://github.com/bitsbybhargav/leetcode/blob/main/570-managers-with-at-least-5-direct-reports/managers-with-at-least-5-direct-reports.sql): solution sql · Aggregation over employee-manager relationships. · `570-managers-with-at-least-5-direct-reports/managers-with-at-least-5-direct-reports.sql`
- [Sales person](https://github.com/bitsbybhargav/leetcode/blob/main/607-sales-person/README.md): problem spec · Exclude salespeople tied to a banned customer. · `607-sales-person/README.md`
- [Sales person](https://github.com/bitsbybhargav/leetcode/blob/main/607-sales-person/sales-person.sql): solution sql · Anti-join / exclusion query across sales tables. · `607-sales-person/sales-person.sql`
- [Not boring](https://github.com/bitsbybhargav/leetcode/blob/main/620-not-boring-movies/README.md): problem spec · Filter movies by odd ID and a text constraint. · `620-not-boring-movies/README.md`
- [Not boring](https://github.com/bitsbybhargav/leetcode/blob/main/620-not-boring-movies/not-boring-movies.sql): solution sql · Conditional filter over movie rows. · `620-not-boring-movies/not-boring-movies.sql`
- [Swap sex](https://github.com/bitsbybhargav/leetcode/blob/main/627-swap-sex-of-employees/README.md): problem spec · Update employee sex values in place. · `627-swap-sex-of-employees/README.md`
- [Swap sex](https://github.com/bitsbybhargav/leetcode/blob/main/627-swap-sex-of-employees/swap-sex-of-employees.sql): solution sql · In-place mutation using conditional update logic. · `627-swap-sex-of-employees/swap-sex-of-employees.sql`

## Connections

- LeetCode → Problem catalog: describes · Repository README names the collection; problem catalog holds the actual content.
- Problem catalog → Problem spec: organizes · Each problem directory provides local challenge context.
- Problem spec → SQL solution: guides · The README boundary leads to the standalone SQL implementation.
- SQL solution → Tables / result: reads/writes · Queries consume challenge tables and produce a result set or update rows.
- Combine tables → Combine tables: specifies · Local prompt documents the join task implemented by the SQL file.
- Combine tables → Tables / result: joins · Two-table exercise produces combined rows.
- Dept top salary → Dept top salary: specifies · Department-level salary prompt maps to one SQL solution.
- Dept top salary → Tables / result: ranks · Produces highest-paid employee rows from relational input.
- Dept top three → Dept top three: specifies · Top-three-per-department prompt maps to one SQL solution.
- Dept top three → Tables / result: ranks · Produces departmental top-N rows from input tables.
- Delete duplicates → Delete duplicates: specifies · Duplicate-removal prompt maps to an update/delete statement.
- Delete duplicates → Tables / result: mutates · Solution updates or removes duplicate rows in place.
- Rising temperature → Rising temperature: specifies · Weather prompt maps to a date-based query.
- Rising temperature → Tables / result: filters · Produces rows matching the temperature increase condition.
- Direct reports → Direct reports: specifies · Manager-count prompt maps to an aggregate query.
- Direct reports → Tables / result: aggregates · Counts direct reports per manager.
- Sales person → Sales person: specifies · Sales exclusion prompt maps to an anti-join query.
- Sales person → Tables / result: excludes · Filters out salespeople linked to disallowed customers.
- Not boring → Not boring: specifies · Movie filter prompt maps to a conditional select.
- Not boring → Tables / result: filters · Returns only rows that satisfy the odd-id/title constraints.
- Swap sex → Swap sex: specifies · Swap prompt maps to an in-place update.
- Swap sex → Tables / result: mutates · Updates employee sex values directly.
