Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A comprehensive collection of coding challenges from multiple platforms for lear
| Platform | Focus Area | Problems Solved |
| ------------------------------- | ---------------------------- | --------------- |
| [LeetCode](#leetcode) | Data Structures & Algorithms | 171 |
| [GreatFrontEnd](#greatfrontend) | Frontend Engineering | 13 |
| [GreatFrontEnd](#greatfrontend) | Frontend Engineering | 14 |

## Platforms

Expand All @@ -23,12 +23,6 @@ Various places where I enjoy practicing solving coding challenges:

**Focus**: Data structures, algorithms, and problem-solving patterns

**Progress**:

- Easy: 80 problems
- Medium: 77 problems
- Hard: 14 problems

**Quick Links**:

- [Browse LeetCode Solutions →](./leetcode/)
Expand Down
1 change: 1 addition & 0 deletions greatfrontend/blind-75/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ No problems completed yet

- [Binary Search Tree Kth Smallest Element](./trees/bst-kth-smallest/) - Medium
- [Binary Tree Level Order Traversal](./trees/level-order-traversal/) - Medium
- [Flip Binary Tree](./trees/flip-binary-tree/) - Easy

### Dynamic Programming

Expand Down
42 changes: 42 additions & 0 deletions greatfrontend/blind-75/trees/flip-binary-tree/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Flip Binary Tree ![Shield](https://img.shields.io/badge/Level-Easy-green) ![Shield](https://img.shields.io/badge/Category-Trees-blue)

Link to problem: [https://www.greatfrontend.com/interviews/study/blind75/questions/algo/binary-tree-flip](https://www.greatfrontend.com/interviews/study/blind75/questions/algo/binary-tree-flip)

Given the `root` node of a binary tree, flip the tree by swapping each node's left and right children, then return the root of the flipped tree.

The binary tree is represented by a collection of `TreeNodes`, where each node has optional `left` and `right` child nodes, which are also `TreeNode`s.

A TreeNode has the following interface:

```typescript
interface TreeNode {
val: number;
left: TreeNode | null;
right: TreeNode | null;
}
```

## Input

- `root: TreeNode`: Root node of the tree. Examples display a level-order traversal of the tree

## Examples

```plaintext
Input: root = [2,1,3]
Output: [2,3,1]
Explanation: The left and right children are swapped.

Input: root = [43,null,-55]
Output: [43,-55]
Explanation: The right child becomes the left child after inversion.

Input: root = [12,8,18,6,null,null,20]
Output: [12,18,8,20,null,null,6]
Explanation: The tree is inverted, with left and right children of each node being swapped.
```

## Constraints

- 1 <= Number of nodes <= 100
Comment on lines +19 to +41

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Clarify empty-tree handling in the spec.
The README says root: TreeNode with at least 1 node, but the implementation accepts TreeNode | null. Please align the input/constraints (allow 0 nodes) or enforce non-null in code. As per coding guidelines, ...

🤖 Prompt for AI Agents
In `@greatfrontend/blind-75/trees/flip-binary-tree/README.md` around lines 19 -
41, The README currently specifies `root: TreeNode` and "1 <= Number of nodes <=
100" but the implementation accepts `TreeNode | null`; update the spec to
reflect empty-tree handling by allowing `root: TreeNode | null` (or "0 <= Number
of nodes <= 100") and add an example for `root = []`/`null`, or alternatively
change the implementation to require non-null by removing `null` from the
function signature and ensuring callers construct a non-empty tree; reference
the `root` type in README and the function signature that accepts `TreeNode |
null` to keep docs and code consistent.

- -100 <= `TreeNode.val` <= 100
23 changes: 23 additions & 0 deletions greatfrontend/blind-75/trees/flip-binary-tree/flip-binary-tree.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export interface TreeNode {
val: number;
left: TreeNode | null;
right: TreeNode | null;
}

/**
* @time O(n) where n is each node in the tree
* @space O(h) where h is the height of the tree
Comment on lines +8 to +9

Copilot AI Jan 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSDoc tags should include hyphens after @time and @space for consistency with other files in the repository. Other GreatFrontEnd solutions use the format @time - and @space - (with hyphens). For example, see array-product-excluding-current.ts and binary-tree-level-order-traversal.ts which use this format.

Copilot generated this review using guidance from repository custom instructions.
*/
export function flipBinaryTree(root: TreeNode | null): TreeNode | null {
if (root === null) {
return null;
}

const rightNode = flipBinaryTree(root.right);
const leftNode = flipBinaryTree(root.left);

root.left = rightNode;
root.right = leftNode;

return root;
}
Loading