> For the complete documentation index, see [llms.txt](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures.md).

# Data Structures

- [Array & List](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array.md)
- [Find Pivot Index](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/find-pivot-index.md)
- [Largest Number At Least Twice of Others](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/largest-number-at-least-twice-of-others.md)
- [Plus One](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/plus-one.md)
- [Diagonal Traverse](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/diagonal-traverse.md)
- [Spiral Matrix](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/spiral-matrix.md)
- [Pascal's Triangle](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/pascals-triangle.md)
- [Implement strStr()](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/implement-strstr.md)
- [Add Binary](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/add-binary.md)
- [Duplicate Counts](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/duplicate-counts.md)
- [Find Duplicates](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/find-duplicates.md)
- [Reverse String](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/reverse-string.md)
- [Array Partition I](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/array-partition-i.md)
- [Two Sum II - Input array is sorted](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/two-sum-ii-input-array-is-sorted.md)
- [Remove Element](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/remove-element.md)
- [Max Consecutive Ones](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/max-consecutive-ones.md)
- [Minimum Size Subarray Sum](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/minimum-size-subarray-sum.md)
- [Reverse Words in a String](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/reverse-words-in-a-string.md)
- [Reverse Words in a String III](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/reverse-words-in-a-string-iii.md)
- [Remove Duplicates from Sorted Array](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/remove-duplicates-from-sorted-array.md)
- [Move Zeroes](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/move-zeroes.md)
- [Rotate Array](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/rotate-array.md)
- [Rotate Image](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/rotate-image.md)
- [Best Time to Buy and Sell Stock](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/best-time-to-buy-and-sell-stock.md)
- [Best Time to Buy and Sell Stock II](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/best-time-to-buy-and-sell-stock-ii.md)
- [Valid Anagram](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/valid-anagram.md)
- [3Sum](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/3sum.md)
- [String to Integer (atoi)](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/string-to-integer-atoi.md)
- [Count and Say](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/count-and-say.md)
- [Merge Sorted Array](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/merge-sorted-array.md)
- [Shuffle an Array](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/shuffle-an-array.md)
- [Max Area of Island](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/array/max-area-of-island.md)
- [Matrix](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/matrix.md)
- [Stack](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/stack.md)
- [Valid Parentheses](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/stack/valid-parentheses.md)
- [Min Stack](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/stack/min-stack.md)
- [Queue](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/queue.md)
- [Linked List](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list.md)
- [Design Linked List](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list/design-linked-list.md)
- [Design Doubly Linked List](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list/design-doubly-linked-list.md)
- [Find Middle Element](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list/find-middle-element.md)
- [Doubly Linked List](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list/doubly-linked-list.md)
- [Cyclic Linked List](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list/cyclic-linked-list.md)
- [Linked List Cycle II](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list/linked-list-cycle-ii.md)
- [Find Nth Element from End](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list/find-nth-element-from-end.md)
- [Remove Nth Node From End of List](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list/remove-nth-node-from-end-of-list.md)
- [Add Two Numbers](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list/add-two-numbers.md)
- [Merge Two Sorted Lists](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list/merge-two-sorted-lists.md)
- [Remove Nth Node From End of List](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list/remove-nth-node-from-end-of-list-1.md)
- [Reverse Linked List](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list/reverse-linked-list.md)
- [Remove Linked List Elements](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list/remove-linked-list-elements.md)
- [Odd Even Linked List](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list/odd-even-linked-list.md)
- [Design Doubly Linked List](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list/design-doubly-linked-list-1.md)
- [Flatten a Multilevel Doubly Linked List](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list/flatten-a-multilevel-doubly-linked-list.md)
- [Rotate List](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list/rotate-list.md)
- [Copy List with Random Pointer](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list/copy-list-with-random-pointer.md)
- [Insert into a Cyclic Sorted List](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list/insert-into-a-cyclic-sorted-list.md)
- [Delete Node in a Linked List](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list/delete-node-in-a-linked-list.md)
- [Palindrome Linked List](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/linked-list/palindrome-linked-list.md)
- [Set](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/hash-table.md)
- [Intersection of Two Arrays](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/hash-table/intersection-of-two-arrays.md)
- [Single Number](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/hash-table/single-number.md)
- [Contains Duplicate](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/hash-table/contains-duplicate.md)
- [Contains Duplicate II](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/hash-table/contains-duplicate-ii.md)
- [Jewels and Stones](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/hash-table/jewels-and-stones.md)
- [Longest Substring Without Repeating Characters](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/hash-table/longest-substring-without-repeating-characters.md)
- [Two Sum III - Data structure design](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/hash-table/two-sum-iii-data-structure-design.md)
- [Valid Sudoku](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/hash-table/valid-sudoku.md)
- [Missing Number](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/hash-table/missing-number.md)
- [Map](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/map.md)
- [Two Sum](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/map/two-sum.md)
- [Isomorphic Strings](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/map/isomorphic-strings.md)
- [Minimum Index Sum of Two Lists](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/map/minimum-index-sum-of-two-lists.md)
- [First Unique Character in a String](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/map/first-unique-character-in-a-string.md)
- [Intersection of Two Arrays II](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/map/intersection-of-two-arrays-ii.md)
- [Logger Rate Limiter](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/map/logger-rate-limiter.md)
- [Group Anagrams](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/map/group-anagrams.md)
- [Group Shifted Strings](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/map/group-shifted-strings.md)
- [Find Duplicate Subtrees](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/map/find-duplicate-subtrees.md)
- [4Sum II](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/map/4sum-ii.md)
- [Top K Frequent Elements](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/map/top-k-frequent-elements.md)
- [Unique Word Abbreviation](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/map/unique-word-abbreviation.md)
- [Insert Delete GetRandom O(1)](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/map/insert-delete-getrandom-o1.md)
- [Binary Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-tree.md)
- [Binary Tree Preorder Traversal](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-tree/binary-tree-preorder-traversal.md)
- [Binary Tree Inorder Traversal](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-tree/binary-tree-inorder-traversal.md)
- [Binary Tree Postorder Traversal](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-tree/binary-tree-postorder-traversal.md)
- [Binary Tree Level Order Traversal](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-tree/binary-tree-level-order-traversal.md)
- [Maximum Depth of Binary Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-tree/maximum-depth-of-binary-tree.md)
- [Symmetric Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-tree/symmetric-tree.md)
- [Path Sum](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-tree/path-sum.md)
- [Balanced Binary Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-tree/balanced-binary-tree.md)
- [Count Univalue Subtrees](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-tree/count-univalue-subtrees.md)
- [Construct Binary Tree from Inorder and Postorder Traversal](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-tree/construct-binary-tree-from-inorder-and-postorder-traversal.md)
- [Construct Binary Tree from Preorder and Inorder Traversal](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-tree/construct-binary-tree-from-preorder-and-inorder-traversal.md)
- [Populating Next Right Pointers in Each Node](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-tree/populating-next-right-pointers-in-each-node.md)
- [Lowest Common Ancestor of a Binary Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-tree/lowest-common-ancestor-of-a-binary-tree.md)
- [Serialize and Deserialize Binary Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-tree/serialize-and-deserialize-binary-tree-go-to-discuss.md)
- [Median of Two Sorted Arrays](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-tree/median-of-two-sorted-arrays.md)
- [Invert Binary Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-tree/invert-binary-tree.md)
- [Find K-th Smallest Pair Distance](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-tree/find-k-th-smallest-pair-distance.md)
- [Split Array Largest Sum](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-tree/split-array-largest-sum.md)
- [Heap](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/heap.md)
- [Binary Search Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-search-tree.md)
- [Validate Binary Search Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-search-tree/validate-binary-search-tree.md)
- [Inorder Successor in BST](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-search-tree/inorder-successor-in-bst.md)
- [Binary Search Tree Iterator](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-search-tree/binary-search-tree-iterator.md)
- [Search in a Binary Search Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-search-tree/search-in-a-binary-search-tree.md)
- [Insert into a Binary Search Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-search-tree/insert-into-a-binary-search-tree.md)
- [Delete Node in a BST](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-search-tree/delete-node-in-a-bst.md)
- [Kth Largest Element in a Stream](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-search-tree/kth-largest-element-in-a-stream.md)
- [Lowest Common Ancestor of a Binary Search Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-search-tree/lowest-common-ancestor-of-a-binary-search-tree.md)
- [Contains Duplicate III](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-search-tree/contains-duplicate-iii.md)
- [Height-Balanced BST](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-search-tree/height-balanced-bst.md)
- [Balanced Binary Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-search-tree/height-balanced-bst/balanced-binary-tree.md)
- [Convert Sorted Array to Binary Search Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/binary-search-tree/height-balanced-bst/convert-sorted-array-to-binary-search-tree.md)
- [Map](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/map-1.md)
- [N-ary Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/n-ary-tree.md)
- [N-ary Tree Preorder Traversal](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/n-ary-tree/n-ary-tree-preorder-traversal.md)
- [N-ary Tree Postorder Traversal](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/n-ary-tree/n-ary-tree-postorder-traversal.md)
- [N-ary Tree Level Order Traversal](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/n-ary-tree/n-ary-tree-level-order-traversal.md)
- [Maximum Depth of N-ary Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/n-ary-tree/maximum-depth-of-n-ary-tree.md)
- [Encode N-ary Tree to Binary Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/n-ary-tree/encode-n-ary-tree-to-binary-tree.md)
- [Serialize and Deserialize N-ary Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/n-ary-tree/serialize-and-deserialize-n-ary-tree.md)
- [Trie](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/trie.md)
- [Implement Trie (Prefix Tree)](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/trie/implement-trie-prefix-tree.md)
- [Map Sum Pairs](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/trie/map-sum-pairs.md)
- [Replace Words](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/trie/replace-words.md)
- [Design Search Autocomplete System](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/trie/design-search-autocomplete-system.md)
- [Maximum XOR of Two Numbers in an Array](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/trie/maximum-xor-of-two-numbers-in-an-array.md)
- [Add and Search Word - Data structure design](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/trie/add-and-search-word-data-structure-design.md)
- [Word Search II](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/trie/word-search-ii.md)
- [Word Squares](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/trie/word-squares.md)
- [Longest Common Prefix](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/trie/longest-common-prefix.md)
- [Palindrome Pairs](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/trie/palindrome-pairs.md)
- [Balanced Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/balanced-tree.md)
- [B-Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/balanced-tree/b-tree.md)
- [Red-black Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/balanced-tree/red-black-tree.md)
- [AVL Tree](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/balanced-tree/avl-tree.md)
- [Graph](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/graph.md)
- [A\* Search](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/graph/a-search.md)
- [Breadth First Search](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/graph/breadth-first-search.md)
- [Depth First Search](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/graph/depth-first-search.md)
- [Dijkstra Algorithm](https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures/graph/dijkstra-algorithm.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ondrej-kvasnovsky-2.gitbook.io/algorithms/data-structures.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
