Segment Tree LeetCode Problems: All 41, With Python Solutions
Every problem in this library that LeetCode tags Segment Tree — 41 in total, 33 of them with a complete Python solution, a worked example and the time and space complexity of the approach.
- 41 problems
- 0 Easy
- 11 Medium
- 30 Hard
Segment Tree problems by difficulty
Problems with a complete Python solution are listed first, then by ascending problem number.
Medium (11)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 307 | Range Sum Query - Mutable | Medium | Design, Binary Indexed Tree, Segment Tree +2 |
| 406 | Queue Reconstruction by Height | Medium | Binary Indexed Tree, Segment Tree, Array +1 |
| 673 | Number of Longest Increasing Subsequence | Medium | Binary Indexed Tree, Segment Tree, Array +1 |
| 729 | My Calendar I | Medium | Design, Segment Tree, Array +2 |
| 731 | My Calendar II | Medium | Design, Segment Tree, Array +3 |
| 1395 | Count Number of Teams | Medium | Binary Indexed Tree, Segment Tree, Array +1 |
| 2080 | Range Frequency Queries | Medium | Design, Segment Tree, Array +2 |
| 2424 | Longest Uploaded Prefix | Medium | Union Find, Design, Binary Indexed Tree +5 |
| 308 | Range Sum Query 2D - MutablePremium | Medium | Design, Binary Indexed Tree, Segment Tree +2 |
| 2031 | Count Subarrays With More Ones Than ZerosPremium | Medium | Binary Indexed Tree, Segment Tree, Array +5 |
| 2907 | Maximum Profitable Triplets With Increasing Prices IPremium | Medium | Binary Indexed Tree, Segment Tree, Array |
Hard (30)
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 218 | The Skyline Problem | Hard | Binary Indexed Tree, Segment Tree, Array +5 |
| 315 | Count of Smaller Numbers After Self | Hard | Binary Indexed Tree, Segment Tree, Array +4 |
| 327 | Count of Range Sum | Hard | Binary Indexed Tree, Segment Tree, Array +4 |
| 493 | Reverse Pairs | Hard | Binary Indexed Tree, Segment Tree, Array +4 |
| 699 | Falling Squares | Hard | Segment Tree, Array, Ordered Set |
| 715 | Range Module | Hard | Design, Segment Tree, Ordered Set |
| 732 | My Calendar III | Hard | Design, Segment Tree, Binary Search +2 |
| 850 | Rectangle Area II | Hard | Segment Tree, Array, Ordered Set +1 |
| 1157 | Online Majority Element In Subarray | Hard | Design, Binary Indexed Tree, Segment Tree +2 |
| 1505 | Minimum Possible Integer After at Most K Adjacent Swaps On Digits | Hard | Greedy, Binary Indexed Tree, Segment Tree +1 |
| 1521 | Find a Value of a Mysterious Function Closest to Target | Hard | Bit Manipulation, Segment Tree, Array +1 |
| 1622 | Fancy Sequence | Hard | Design, Segment Tree, Math |
| 1649 | Create Sorted Array through Instructions | Hard | Binary Indexed Tree, Segment Tree, Array +4 |
| 1687 | Delivering Boxes from Storage to Ports | Hard | Segment Tree, Queue, Array +4 |
| 2179 | Count Good Triplets in an Array | Hard | Binary Indexed Tree, Segment Tree, Array +4 |
| 2213 | Longest Substring of One Repeating Character | Hard | Segment Tree, Array, String +1 |
| 2276 | Count Integers in Intervals | Hard | Design, Segment Tree, Ordered Set |
| 2286 | Booking Concert Tickets in Groups | Hard | Design, Binary Indexed Tree, Segment Tree +1 |
| 2407 | Longest Increasing Subsequence II | Hard | Binary Indexed Tree, Segment Tree, Queue +4 |
| 2426 | Number of Pairs Satisfying Inequality | Hard | Binary Indexed Tree, Segment Tree, Array +4 |
| 2569 | Handling Sum Queries After Update | Hard | Segment Tree, Array |
| 2659 | Make Array Empty | Hard | Greedy, Binary Indexed Tree, Segment Tree +4 |
| 2736 | Maximum Sum Queries | Hard | Stack, Binary Indexed Tree, Segment Tree +4 |
| 2926 | Maximum Balanced Subsequence Sum | Hard | Binary Indexed Tree, Segment Tree, Array +2 |
| 2940 | Find Building Where Alice and Bob Can Meet | Hard | Stack, Binary Indexed Tree, Segment Tree +4 |
| 683 | K Empty SlotsPremium | Hard | Binary Indexed Tree, Segment Tree, Queue +5 |
| 2158 | Amount of New Area Painted Each DayPremium | Hard | Segment Tree, Array, Ordered Set |
| 2519 | Count the Number of K-Big IndicesPremium | Hard | Binary Indexed Tree, Segment Tree, Array +4 |
| 2916 | Subarrays Distinct Element Sum of Squares II | Hard | Binary Indexed Tree, Segment Tree, Array +1 |
| 2921 | Maximum Profitable Triplets With Increasing Prices IIPremium | Hard | Binary Indexed Tree, Segment Tree, Array |
Keep exploring
All LeetCode topicsEvery tag with a page of its own, with the number of problems behind each.LeetCode patternsThe techniques themselves, with a Python template and complexity for each.Curated study listsBlind 75, NeetCode 150 and three more, grouped by pattern.Easy problemsStart here when the data structure is new rather than the problem.
Other topics
- Array1,569
- String672
- Hash Table588
- Math485
- Dynamic Programming481
- Sorting392
- Greedy346
- Depth-First Search289
- Binary Search253
- Database249
- Tree225
- Breadth-First Search223
- Matrix216
- Two Pointers201
- Bit Manipulation194
- Binary Tree174
- Heap (Priority Queue)163
- Prefix Sum157
- Stack157
- Simulation144
- Graph138
- Counting126
- Design122
- Sliding Window116
When the Segment Tree problem arrives live
Stealth Interview is a desktop app for macOS and Windows. It reads the coding problem off your screen, returns a working solution with a step-by-step explanation and its time and space complexity, and transcribes what the interviewer is saying — while staying invisible to screen sharing.