---
title: "Discussion on \"How to reduce the time complexity of nested loops\" | Hashnode"
description: "Discussion on \"How to reduce the time complexity of nested loops\". In this post I'll demonstrate a way to understand, analyse and reduce the time complexity on algorithms, specially on nested loops.\nThe examples will use Ruby but it can be translated to any programming language.\nProblem\nWorking throughout a variety ..."
url: "https://hashnode.com/posts/how-to-reduce-the-time-complexity-of-nested-loops/61abed81a375fb2266f3d77b"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How to reduce the time complexity of nested loops](https://leandronsp.com/how-to-reduce-the-time-complexity-of-nested-loops?utm_source=hashnode&utm_medium=feed)

In this post I'll demonstrate a way to understand, analyse and reduce the time complexity on algorithms, specially on nested loops. The examples will use Ruby but it can be translated to any programming language. Problem Working throughout a variety ...

Dec 4, 2021 · 4 min read · leandronsp.com  
Read the article

-   [#ruby](https://hashnode.com/tag/ruby)
-   [#programming](https://hashnode.com/tag/programming)
-   [#algorithms](https://hashnode.com/tag/algorithms)

## Written by

[Leandro Proença](https://hashnode.com/@leandronsp)

@leandronsp · Lisbon

  
[View profile](https://hashnode.com/@leandronsp)

Software Developer

15+ years programming, here I will share my thoughts on programming and engineering practices. In my spare time I like playing chess and the Piano.

## Responses 5

Markdown supported · ⌘↵ to post

[sean doe](https://hashnode.com/@seandoe1990)

[Dec 13, 2021](https://hashnode.com/posts/how-to-reduce-the-time-complexity-of-nested-loops/61abed81a375fb2266f3d77b/comment/61b79343d2a5c9036e6efc8a)

Hello. great post at you! saw similar material in the article [has science gone too far](https://privatewriting.net/blog/science-has-the-potential-to-destroy-us) well written, competently. I often order term papers and essays from them. inexpensive and always of high quality. and I recommend you too

[Leandro Proença](https://hashnode.com/@leandronsp)

[Dec 14, 2021](https://hashnode.com/posts/how-to-reduce-the-time-complexity-of-nested-loops/61abed81a375fb2266f3d77b/comment/61b79343d2a5c9036e6efc8a#reply-61b88e84d2a5c9036e6f0c92)

thank you, I'll take a look at it

[Jan-Magnus Kister](https://hashnode.com/@JanMagnusDev)

[Dec 9, 2021](https://hashnode.com/posts/how-to-reduce-the-time-complexity-of-nested-loops/61abed81a375fb2266f3d77b/comment/61b1bbe91907c16be2edfcf6)

If you are stuck, just throw a HashMap at the problem :D

[Leandro Proença](https://hashnode.com/@leandronsp)

[Dec 9, 2021](https://hashnode.com/posts/how-to-reduce-the-time-complexity-of-nested-loops/61abed81a375fb2266f3d77b/comment/61b1bbe91907c16be2edfcf6#reply-61b1dd1e6a81cf6b31dfc017)

not sure if you are being ironic. is it a problem in this case?

[Marcelo Zárate](https://hashnode.com/@marcelozarate)

[Dec 7, 2021](https://hashnode.com/posts/how-to-reduce-the-time-complexity-of-nested-loops/61abed81a375fb2266f3d77b/comment/61af65bb9759e33b4eaf8d04)

Muito bom artigo, parabéns! Even when I'm not a ruby coder, the point was crystal clear. Maybe an article on Big O optimizations other than O(n²)?

[Priyank Patel](https://hashnode.com/@priyank)

[Dec 7, 2021](https://hashnode.com/posts/how-to-reduce-the-time-complexity-of-nested-loops/61abed81a375fb2266f3d77b/comment/61aeda059dc5a836391bbb28)

This is one of the top point in my code review checklist.

[Devang Hingu](https://hashnode.com/@devanghingu)

[Dec 7, 2021](https://hashnode.com/posts/how-to-reduce-the-time-complexity-of-nested-loops/61abed81a375fb2266f3d77b/comment/61aeda059dc5a836391bbb28#reply-61af56679759e33b4eaf8adf)

Me too.! mostly developer makes such mistake when we writes like step by step instead of planning.

[Aman gupta](https://hashnode.com/@codecraft26)

[Dec 6, 2021](https://hashnode.com/posts/how-to-reduce-the-time-complexity-of-nested-loops/61abed81a375fb2266f3d77b/comment/61ae94f09dc5a836391bb822)

Both
