💡 Are you a programmer? How do you approach while solving a problem?
A must-read for beginners.
🧵 👇
P.S: This thread is not meant to teach you about any specific approach. Rather I would give more emphasis on "understanding what is asked" and "how to program it efficiently".
✪ Problem 1️⃣
Let's take "Printing the Asterisks" problem. It's simple, yet tricky sometimes.
Print below on screen
✪
✪✪
✪✪✪
✪✪✪✪
✪✪✪✪✪
When I see it, I have 👇 understandings
There are total 5 lines to print
1st line to have 1 ✪, 2nd line to have 2 ✪. So, kth line would have k ✪
What are yours?
With ☝️ understandings, it became easy for me to program it.
✪ Pseudo Code
→ Iterate 'i' from 1 to 5
→ For each 'i', print 'i' number of ✪ and a 'new line' character
✪ Alternate Problem 1️⃣
If above problem is modified and asked to print below on screen
✪✪✪✪✪
✪✪✪✪
✪✪✪
✪✪
✪
Understandings are 👇
→ There are total 5 lines to print
→ 1st line to have 5 ✪, 2nd line to have 4 ✪. 5th line to have 1 ✪
For programming, we need to find out a formula for how many ✪ in 'i'th line.
✪ Observing the Pattern
Line/Asterisks 1/5 2/4 3/3 4/2 5/1
What do you observe? For me, the pattern is (Line + Asterisks) results always to 6.
What is 6? Any guess?
To me it's (Total number of Lines + 1). What do you say?
So, 'i'th line will have (6 - i) asterisks.
✪ Pseudo Code
→ Iterate 'i' from 1 to 5
→ For each 'i', print '6 - i' number of ✪ and a 'new line' character
Good that, we solved this problem and understood about finding a pattern.
But now, think for some time. Can this be done in a better approach? The solution lies in the picture itself.
Don't you think the 1st picture is just turned upside down to result into 2nd picture?
How can we represent "upside down" programmatically?
Can we say "Iterate from 5 to 1"? Think.
✪ Pseudo Code
→ Iterate 'i' from 5 to 1
→ For each 'i', print 'i' number of ✪ and a 'new line' character
So, what do we observe?
✪ We can solve a problem in many ways
✪ The approach we choose defines the complexity of the solution
✪ Approach is refined by our looking at picture in a different way.
Trust me. Nobody can teach another person how to approach for a solution. Even a 1 year old kid finds solutions to his problems himself. That's how we humans are.
The approach gets sharp with practice and experience.
One best way is to change the original problem to some extent. Then observe how the solution is changing as well. Try to refine your approach for finding a better solution every time.
We come to the end of this 🧵 Hope you find it useful.
👋 I am Swapna and I write contents on DSA, JavaScript and Python
To never miss any content from me,
✅ Follow @swapnakpanda
🔔 Turn on Notifications
♥️ Like the tweet
🔁 The first tweet
💬 Your feedback about the content
Share how do you approach while solving a problem?
Mention how does that help you in solving complex problems?
• • •
Missing some Tweet in this thread? You can try to
force a refresh
1️⃣ Introduction to RDBMS
2️⃣ Normalisation
3️⃣ Introduction to SQL
4️⃣ Tables and Fields
5️⃣ Constraints
6️⃣ Index
7️⃣ DML Operations
8️⃣ Joins
9️⃣ Set Operations
1️⃣ Introduction to RDBMS
✪ What is a Database?
✪ What are different types of Databases?
✪ What is DBMS?
✪ What is difference between Database and DBMS?
✪ What is RDBMS?
✪ Which are popular RDBMS vendors?
✪ What is ACID property in Database?
1️⃣ Introduction
2️⃣ JSX
3️⃣ Virtual DOM
4️⃣ Component
5️⃣ States and Props
6️⃣ Data Binding
7️⃣ Component Rendering
8️⃣ Hooks Introduction
1️⃣ Introduction
✪ What is React?
✪ What is the current version of React?
✪ What are core features of React?
✪ What are advantages using React?
✪ Where shouldn't we use React?
✪ What is SPA?
✪ When will a SPA run slower/faster?
1️⃣ Data Types
2️⃣ Boolean
3️⃣ Number
4️⃣ Logical Operators
5️⃣ Comparison Operators
6️⃣ Arithmetic Operators
1️⃣ Data Types
✪ What all data types does JavaScript provide?
✪ How to find out data type of a value? (which operator to use)
✪ What is type coercion?
✪ Any significant difference between "undefined" and "null"?
✪ What is the type of undefined?
✪ What is the type of null?