# Making Counting Sort work with Negative Values

**URL:** https://forum.kirupa.com/t/making-counting-sort-work-with-negative-values/667168
**Category:** programming
**Created:** [May 28, 2024, 11:15pm UTC](https://forum.kirupa.com/t/making-counting-sort-work-with-negative-values/667168 "2024-05-28T23:15:32Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)
#### Post date: [May 28, 2024, 11:15pm UTC](https://forum.kirupa.com/t/making-counting-sort-work-with-negative-values/667168/1 "2024-05-28T23:15:32Z")

</div>

Hot off my mistake in the [earlier thread](http://forum.kirupa.com/t/why-counting-sort-and-radix-sort-dont-work-with-negative-numbers/667105/5), I figured I’ll go ahead and propose a solution to modify counting sort to work with negative values as well! 🙂

> **[Making Counting Sort Work with Negative Values](https://www.kirupa.com/data_structures_algorithms/making_counting_sort_work_with_negative_values.htm)**
>
> By default, counting sort does not work with negative values. It doesn't have to be that way, so let's look at why this is the case and how to fix it to work with both negative and positive values.

Hopefully this helps those of you who stumble onto here either from the article or a Google search 🪂

Also, I had way too much fun creating this:

 ![image](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/4/9/4964c9d9ce4b8455bd287513b529e602b1345c68.jpeg)

Cheers,  
Kirupa
