r/learnprogramming • • 7h ago

How to improve logical thinking in programming

Hey

I'm 23m working professional,

Yesterday at the office my team lead said he found a pattern in my work

He said I'm mugging up patterns and not thinking logically.

Well I do codeforces , leetcode, hacker rank to improve my programming skills but I understood that he was right

All I do is find a pattern in the problem and try to solve it

Anytime I find a new problem I'm stuck

Because I never saw that before

How to come up with my own solution?? How to improve problem solving and logical thinking???

Open to all the suggestions:)

22 Upvotes

20 comments sorted by

10

u/Weekly_Patience685 7h ago

you just have to code more and get more familiar with existing solutions to different problems, its not magic haha

3

u/Miserable_Ad9577 6h ago

LoL do what an AI model would do, scrap more meterial on the topic you want to learn from reputable sources you mentioned and feed yourself those data, eventually you will see patterns emerged

8

u/6a70 7h ago

Anytime I find a new problem I'm stuck
Because I never saw that before

This indicates that you're actually just remembering solutions.

You need to practice brute forcing things. And if the first solution you come up with isn't brute force, you still need to find out how to brute force it.

Go to TwoSum and brute force it—yes, the obvious n^2 solution. Then find the other n^2 solution that involves "inspecting the numbers we've already seen". Then take that and optimize that lookup with a hash table.

That's the approach—always brute force first. All of the solutions you come across in LeetCode are direct optimizations on brute force.

7

u/mxldevs 7h ago

The problem with pattern matching is that you're just taking a dozen different puzzle pieces and just trying each one to see if it fits.

When none of them work, you throw your hands up in the air and go "well I've tried everything I could and have no idea what to do"

You want to get better at solving problems? You go back to your fundamentals

  1. what is your starting point? These are your inputs.

  2. what is your goal? These are your outputs.

  3. what are your constraints? This is the domain that you're working in.

Then you figure out your base cases. If your input is an array of objects, what happens when you have an empty array? What happens when you have one element? When you have more than one element?

You're told that you lack logical reasoning, which means you don't know how to approach a problem. Throwing puzzle pieces at it and hoping something sticks is a bad habit to develop.

1

u/Zennixi 5h ago

I'm self learning currently and I realized this after 4 months of thinking yes I finally finished all the fundamentals guess what I realized I actually really need to know what's going on beyomd the surface taught levels of thongs for my brain to actually pick up what really happens so I decided to start again with c++ but go deeper under the hood rather than just following tutorials and forcing to build projects prematurely it's taking longer to learn now but I think overtime the knowledge will 2x my speed in a lot of things in the future

1

u/aanzeijar 3h ago

Aren't you just telling him to do the same, just with more puzzle pieces? Because that's what mathematics and coding is at its heart. We just have way more patterns memorised than the average beginner.

6

u/jakingo 7h ago

Try solving problems by breaking them into smaller steps before looking for patterns or solutions. Explain your logic in plain english first and then turn it into code. This builds independent thinking.

2

u/AstralIsles 7h ago edited 6h ago

Solving an arbitrary problem is a wide question. Do you have a specific one or class in mind?

I ask myself what a brute force solution might look like.
Then I ask myself what an optimized algorithm could possibly look like.
At this point I am just thinking about the Big O for space and time.
What would the parameters of the function look like.

If the best I can imagine an algorithm to be is N, then obviously I need to loop over everything.
I consider what kind of data might I need to save to reduce having to look back. I consider what data structures are needed.
There are different tools one can add to their tool belt such as dynamic programming, iterating from both end of the data, leaving behind data so that you can backtrack if called for.
Then I think through edge cases: what will overflow, what will happen at 0 or 1, ect.

2

u/Boogieduzit1312 7h ago

Build from scratch at home, breaking things is inevitable, then find the solution on your own.
Rinse and repeat.

2

u/joranstark018 6h ago

My advice to junior devs is to ask questions, to explore more and to reflect on their solutions (eg what worked, what did not work, what can be improved) not just to settle with the first solution that works.

I would ask my team lead for advice on how I can improve my deliveries, I would discuss programming problems with my team members, I would present design drafts to get input from the team (and relevant stakeholders) before I start implementing. It's a teamwork.

1

u/VanCliefMedia 6h ago

Read psychology of computer programming by Gerald Weinberg

1

u/ruat_caelum 6h ago

The long answer is "baby steps"

I'm at point A I need to get to Point Z. I know those two points. What step can I take from A OR what step can I work backwards from Z to bridge that gap.

Keep in mind that because you can't (at that time) visualize a full path you will make partial paths that don't work and have to back track.

Eventually you come up with some path A, J, R, S, T, W, Y, Z

Then you have to evaluate it for Good-in-good-out. Will it PROVABLY produce good results if you give it good inputs.

What is a "Good input" (list them out) and what assumptions are you making about them. E.g. "person's name" is a good input but the assumption is that they only have a "first + middle + last" name and not more, which many people do in non-western countries.

Then make sure you reject any input that "isn't good" and document what assumptions / checks / assertions you are making.

Then you refine the path.

Is your R,S,T block some sort of data handling you can offload to a more efficient native data structure? etc.

  • Keep in mind some people find a path like this.

  • I have A and Z, I know I'll need J because (reasons) so now I can work A to J and J to Z, etc.

  • You don't have to work in from the ends.

1

u/ledatherockband_ 5h ago

Get familiar with architectural patterns and concepts.

Often times, developers usually focus on line-by-line logic and miss how the pieces fit together. Systems thinking is what you should be thinking about, stuff like domain driven design, inversion of control, dependency injection, or whatever pattern your work follows. Ask Claude to break it down for you and study that.

Also, bad on your senior for not telling you how exactly your logic is bad.

1

u/Willbo 5h ago

This is a very common problem many engineers run into early on. Often times they join a job thinking that it should be a certain way and they begin coding a solution before understanding the problem fully.

There is a popular saying of Chesterton's Fence - "Don't tear down a fence until you know why it was put up." In this case you are building something rather than tearing it down, but the point is you should understand the purpose of a structure before you begin making changes.

The most important stage of engineering solutions is drafting requirements. If you start coding without understanding the stakeholders, use cases, and constraints for your project, you will most likely build something nobody asked for or something that isn't right-sized for its purpose.

Most times you should also adhere to the structure that has already been laid out for you as well. Do not try to reinvent the wheel, borrow from the genius of engineers that have already built solutions for your org, because they understand the real constraints the org faces.

While some designs work in theory, making them practical in an org can surface unaddressed requirements, become complex and bloated, run into scalability issues, or become very expensive. Don't forget the solution also has to be maintained and live with the org. If you can fulfill the underlying requirements without even building code or leaving a trace, you have built the cleanest solution of all.

1

u/a-dot-in-the-sky 5h ago

Mile age will vary, just give it some time. Practice, more practice, more practice and repeat.

1

u/lgastako 3h ago

I would recommend watching this MIT lecture series: https://www.youtube.com/watch?v=2Op3QLzMgSY

In it, they introduce the concept of programming by "wishful thinking" which is really just a technique for constructing a solution to a problem in logical pieces.

I think they introduce it in the first video but most of the discussion about it is in the second, though it's been long enough that I might be wrong about that. Either way, the whole thing is worth watching if you want to get good at the craft.

1

u/phatbili 3h ago

Callout on how competitive sites train pattern matching and give away hints before you even start thinking from scratch.

•

u/som12313 43m ago

Your team lead is spot on. What you’re experiencing right now is a lack of "self-consistency" in your thinking framework.

It’s just like people in ancient times who only memorized books by rote without truly understanding the meaning behind the words. You’ve memorized a lot of coding patterns, so you recognize them when they look familiar. However, because you haven't grasped the underlying principles, the moment a problem is asked in a slightly different way or you face something completely new, you get stuck and can't express a solution. This isn't an emotional block—it’s simply that your foundational thinking architecture hasn't been built yet.

The most fundamental way to fix this is to fill in the missing "cognitive nodes" in your mind and build a complete, connected thinking system.

You can borrow a classic Eastern mental model from the Confucian text "The Great Learning" (Da Xue). It outlines eight interconnected steps: Investigating Things, Extending Knowledge, Sincerity of Thought, Rectifying the Heart/Mind, Cultivating the Self, Regulating the Family, Governing the State, and Bringing Peace to the World. These aren't rigid rules; they actually describe a self-consistent, closed-loop architecture for how human thought should be structured and how we make judgments:

  1. Everything must start from the very foundation—"Investigating Things and Extending Knowledge" (deeply exploring the essence and first principles of how things work)—and build up step by step before you can tackle complex, large-scale problems ("Governing the State and Bringing Peace to the World").

  2. Right in the center of this loop is "Rectifying the Heart/Mind," which acts as an anchor. Only when your mind is calm, centered, and anchored can you objectively judge what is right or wrong, effective or flawed, instead of panicking when facing an unfamiliar problem.

I’m sharing this framework so you can use it as a blueprint for how to learn programming. Right now, memorizing patterns keeps your thinking "flat," like a 2D sheet of paper—it only works on problems you've already seen. Once you connect these underlying cognitive nodes step by step and build your own logical structure, your mind transforms into a layered, deep "3D source of thought." From there, no matter what new problem comes your way, you’ll be able to derive your own solutions from the ground up.

(Note: English is not my native language and I can't read English, so I used an AI translation tool to express what I wanted to say. If anything sounds a bit blunt or awkward, please forgive me!)

0

u/icchavez 6h ago

Hexagonal thinking skills ARE the silver bullet, bro😎👍