• DSA Tutorial
  • Data Structures
  • Linked List
  • Dynamic Programming
  • Binary Tree
  • Binary Search Tree
  • Divide & Conquer
  • Mathematical
  • Backtracking
  • Branch and Bound
  • Pattern Searching

How To Approach A Coding Problem ?

Solving a DSA (Data Structures and Algorithms) Problem is quite tough. In This article, we help you not only solve the problem but actually understand it, It’s not about just solving a problem it’s about understanding the problem. we will help to solve DSA problems on websites like Leetcode, CodeChef, Codeforces, and Geeksforgeeks. the importance of solving a problem is not just limited to job interviews or solve problems on online platform, its about develop a problem solving abilities which is make your prefrontal cortex strong, sharp and prepared it to solve complex problem in future, not only DSA problems also in life.

These steps you need to follow while solving a problem:

– Understand the question, read it 2-3 times. – Take an estimate of the required complexity. – find, edge cases based on the constraints. – find a brute-force solution. ensure it will pass. – Optimize code, ensure, and repeat this step. – Dry-run your solution(pen& paper) on the test cases and edge cases. – Code it and test it with the test cases and edge cases. – Submit solution. Debug it and fix it, if the solution does not work.

How-to-Approach-a-Coding-Problem

Understand The Question

firstly read it 2-3 times, It doesn’t matter if you have seen the question in the past or not, read the question several times and understand it completely. Now, think about the question and analyze it carefully. Sometimes we read a few lines and assume the rest of the things on our own but a slight change in your question can change a lot of things in your code so be careful about that. Now take a paper and write down everything. What is given (input) and what you need to find out (output)? While going through the problem you need to ask a few questions yourself…

  • Did you understand the problem fully?
  • Would you be able to explain this question to someone else?
  • What and how many inputs are required?
  • What would be the output for those inputs
  • Do you need to separate out some modules or parts from the problem?
  • Do you have enough information to solve that question? If not then read the question again or clear it to the interviewer.

                Estimate of the required complexity

Look at the constraints and time limit. This should give you a rough idea of the expected time and space complexity. Use this step to reject the solutions that will not pass the limits. With some practice, you will be able to get an estimate within seconds of glancing at the constraints and limits.

              Find, edge cases 

In most problems, you would be provided with sample input and output with which you can test your solution. These tests would most likely not contain the edge cases. Edge cases are the boundary cases that might need additional handling. Before jumping on to any solution, write down the edge cases that your solution should work on. When you try to understand the problem take some sample inputs and try to analyze the output. Taking some sample inputs will help you to understand the problem in a better way. You will also get clarity that how many cases your code can handle and what all can be the possible output or output range.

Constraints 

0 <= T <= 100

1 <= N <= 1000

-1000 <= value of element <= 1000

Find a brute-force Solution

A brute-force solution for a DSA (Data Structure and Algorithm) problem involves exhaustively checking all possible solutions until the correct one is found. This method is typically very time-consuming and not efficient, but can be useful for small-scale problems or as a way to verify the correctness of a more optimized solution. One example of a problem that could be solved using a brute-force approach is finding the shortest path in a graph. The algorithm would check every possible path until the shortest one is found.

Break Down The Problem

When you see a coding question that is complex or big, instead of being afraid and getting confused that how to solve that question, break down the problem into smaller chunks and then try to solve each part of the problem. Below are some steps you should follow in order to solve the complex coding questions… 

  • Make a flow chart or a UML for the problem at hand.
  • Divide the problem into sub-problems or smaller chunks.
  • Solve the subproblems. Make independent functions for each subproblem.
  • Connect the solutions of each subproblem by calling them in the required order, or as necessary.
  • Wherever it’s required use classes and objects while handling questions (for real-world problems like management systems, etc.)

Optimize your Code

Always try to improve your code. Look back, analyze it once again and try to find a better or alternate solution. We have mentioned earlier that you should always try to write the right amount of good code so always look for the alternate solution which is more efficient than the previous one. Writing the correct solution to your problem is not the final thing you should do. Explore the problem completely with all possible solutions and then write down the most efficient or optimized solution for your code. So once you are done with writing the solution for your code below are some questions you should ask yourself. 

Optimizing a solution in DSA (Data Structure and Algorithm) refers to improving the efficiency of an algorithm by reducing the time and/or space complexity. This can be done by using techniques such as dynamic programming, greedy algorithms, divide and conquer, backtracking, or using more efficient data structures.

It’s important to note that the optimization process is not always straightforward and it can be highly dependent on the specific problem and constraints. The optimization process usually starts with a brute force approach, and then various techniques will be applied to make the algorithm more efficient. The optimization process will often require a trade-off between time and space complexity.

Also, measuring and analyzing the performance of the algorithm is an essential step in the optimization process. The use of mathematical notation and analysis tools like Big O notation and complexity analysis, can help to understand the performance of an algorithm and decide which one is the best.

  • Does this code run for every possible input including the edge cases.
  • Is there an alternate solution for the same problem?
  • Is the code efficient? Can it be more efficient or can the performance be improved?
  • How else can you make the code more readable?
  • Are there any more extra steps or functions you can take out?
  • Is there any repetition in your code? Take it out.

Below is the alternate solution for the same problem of the array which returns even numbers… 

          Dry-run your solution

Dry-running a solution on test cases and edge cases involves manually going through the steps of the algorithm with sample inputs and verifying that the output is correct. This process can help to identify any bugs or errors in the code, as well as ensure that the algorithm is correctly handling all possible inputs, including edge cases.

When dry-running your solution, it’s important to consider both the expected test cases and any unexpected edge cases that may arise. Edge cases are inputs that are at the boundaries of the problem’s constraints, for example, the maximum or minimum values.

To dry-run the solution, you will need to:

  • Write down the sample test case inputs and expected outputs.
  • Go through the steps of the algorithm manually, using the test case inputs.
  • Compare the output of the algorithm to the expected output, to ensure the solution is correct.
  • Repeat the process for each test case and edge case.
  • Dry-running your solution on test cases and edge cases can help you to identify any issues with your algorithm, and make any necessary adjustments before running the code on a computer.

             Code & Test it On Edge Cases

After dry-running your solution and verifying that it is right, the next step is to code it and test it using the test cases and edge cases.

To code the solution, you will need to:

  •  write the code for the algorithm.
  • Make sure to include any necessary data structures and methods.
  • Test the code with sample inputs, including the test cases and edge cases that were used during the dry-run.
  • When testing the code, it’s important to not only check for the expected outputs, but also for any unexpected behavior or errors. Testing with edge cases is especially important as it can reveal bugs or errors that might not be present in other test cases.

It’s also a good practice to test the code with additional test cases and edge cases, to further ensure the correctness and robustness of the solution.

Once the code has been tested and all the bugs have been fixed, you can submit it.

 Submit solution

After coding and testing the solution on the sample test cases, the next step is to submit it, usually to a platform for review or for a contest.

The submission process can depending on the platform, but basically it involves submitting the code and any necessary documentation. After the submission, the solution is usually reviewed by other participants or judges, and feedback is provided on whether the solution is correct or if there are any errors. If the solution is wrong or does not work as expected, the next step is to debug and fix it. Debugging is the process of identifying and resolving errors in the code. This can involve using tools such as a debugger, print statements, or logging to find the source of the problem.

Once the error has been identified, the next step is to fix it. This can involve making changes to the code, data structures, or algorithms used. Once the changes have been made, it’s important to test the solution again to ensure that the error has been resolved and that the solution is correct.

If the solution is correct, you can submit it again or move on to other problems.

It’s important to note that the debugging and fixing process can be an iterative one and it may take several iterations to get the solution working correctly.

author

Similar Reads

  • Competitive Programming

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

Achieve mastery through challenge

Improve your development skills by training with your peers on code kata that continuously challenge and push your coding practice.

problem solving with coding

Sharpen your coding skills

Challenge yourself on small coding exercises called "kata". Each kata is crafted by the community to help you strengthen different coding techniques. Master your current language of choice, or quickly pick up any of the 55+ programming languages supported.

problem solving with coding

Get instant feedback

Solve kata with your coding style right in the browser and use test cases (TDD) to check it as you progress. Retrain with new, creative, and optimized approaches. Find all of the bugs in your programming practice.

problem solving with coding

Earn ranks and honor

Kata code challenges are ranked from beginner to expert level. As you complete higher-ranked kata, you level up your profile and push your software development skills to your highest potential.

problem solving with coding

An engaged software development community

Codewars is a collective effort by its users. They are creators—authoring kata to teach various techniques, solving kata with solutions that enlighten others, and commenting with constructive feedback.

Community members added every month

Kata completed every month

Kata created by our community

Tap into the collective wisdom

Compare your solution with others after each kata for greater understanding. Discuss kata, best practices, and innovative techniques with the community. Have your mind blown by how different other solutions can be from your own.

problem solving with coding

Create your own kata

Author kata that focus on your interests and train specific skill sets. Challenge the community with your insight and code understanding. Create everything from common developer interview questions to challenges that push the limits of your creativity. Gain honor within the coding dojo.

problem solving with coding

What can I use Codewars for?

From beginner to expert and beyond...

Get new perspectives

Solve challenges then view how others solved the same challenge. Pickup new techniques from some of the most skilled developers in the world.

Learn new languages

Solve challenges in a language you are comfortable with, then do it in a language you want to improve with. Level up across different languages.

Compete with peers

Compete against your friends, colleagues, and the community at large. Allow competition to motivate you  towards mastering your craft.

Extremely well done and an excellent example of mastery learning.

problem solving with coding

Ahmed Omran

@this_ahmed

Accidentally got addicted to codewars, oops.

problem solving with coding

Kelly Williams

Build self-confidence

Not sure if you are progressing well as a programmer? Push yourself to your limits and show yourself what you are really made of.

Become a mentor

Lend your expertise to others, either indirectly by contributing great solutions or directly by creating your own kata and reviewing code.

Insights from Codewars staff and community.

Join us live this week

Join us live this week

problem solving with coding

Author's Corner, meet geoffp

problem solving with coding

What's new in Codewars: April highlights

Codewars is built on.

The world's most advanced coding assessment platform for organizations looking to scale their hiring, upskilling, and certification programs.

Achieve mastery through challenge.

Top languages

Welcome to Java! Easy Max Score: 3 Success Rate: 97.04%

Java stdin and stdout i easy java (basic) max score: 5 success rate: 96.80%, java if-else easy java (basic) max score: 10 success rate: 91.44%, java stdin and stdout ii easy java (basic) max score: 10 success rate: 92.91%, java output formatting easy java (basic) max score: 10 success rate: 96.55%, java loops i easy java (basic) max score: 10 success rate: 97.68%, java loops ii easy java (basic) max score: 10 success rate: 97.32%, java datatypes easy java (basic) max score: 10 success rate: 93.73%, java end-of-file easy java (basic) max score: 10 success rate: 97.91%, java static initializer block easy java (basic) max score: 10 success rate: 96.09%, cookie support is required to access hackerrank.

Seems like cookies are disabled on this browser, please enable them to open this website

The 8 Best Coding Challenge Websites to Help You Level Up Your Skills in 2020

The 8 Best Coding Challenge Websites to Help You Level Up Your Skills in 2020

By Daniel Borowski

Despite the lowest unemployment rate in decades, analysts expect technology hiring to continue growing steadily into the 2020s.

That’s great news for recent computer science graduates and developers currently working in the field, but that doesn’t mean ambitious engineers can get complacent.

While there will likely be growth opportunities in the market overall, there are still significant changes happening all the time, and a sense of urgency to keep up with the latest trends.

Today, there are more types of technical roles than ever before, and a continued proliferation of new languages, frameworks, and technologies. Technical employees that want to get ahead should routinely test and refine their skills.

To that end, I’ve put together the following list of platforms where you can level up your skills for any number of roles, from data science to developer operations.

1. freeCodeCamp

Helpful links: Website | Forum | Challenges

Image

Let's begin with freeCodeCamp, which is a great website for beginners who are just getting into coding. They offer all sorts of resources on learning syntax, practicing coding, building projects, and preparing for interviews.

They don’t have as many interactive coding challenges as other sites, but they do offer some fun challenges and interview prep for beginners learning JavaScript.

Novices who are just learning to code for the first time. It’s a great place to learn HTML, CSS, and JavaScript in a fun, interactive way.

Pricing / Premium content

freeCodeCamp is completely free.

2. Coderbyte

Helpful links: Website | Blog | Dev.to | Free Challenges | Premium

Image

My platform, Coderbyte, provides 300+ coding challenges you can solve in an online editor using 10 different programming languages. You can then access official solutions, over 1.5 million user solutions, and read articles on how to efficiently solve the challenges.

Coderbyte is recommended by the top coding bootcamps and companies because of its collection of interview prep challenges.

Coderbyte is perfect for people in the beginner-to-intermediate phase of their careers who are preparing for interviews. There is a library of harder challenges as well for those who like to solve coding problems for fun, but this isn’t primarily a site for competitive programmers.

There are a handful of free challenges on Coderbyte, and then there are hundreds of premium challenges and over 1 million user solutions that are available to members .

3. LeetCode

Helpful links: Website | Discussion | Free Challenges | Premium

Image

LeetCode has a collection of some of the best algorithm challenges online today. The topics they cover require knowledge of data structures such as binary trees, heaps, linked lists, and so on, which is why their challenges are a bit more advanced than some other websites. But the challenges are great if used to prepare for a software engineering interview.

They also have a Mock Interview section that is specifically for job interview preparation. They also host their own coding contests , and they have a great discussion board where people talk about interview questions, jobs, compensation, and other topics related to engineering.

LeetCode is great for intermediate-to-advanced programmers. It might not be the best suited for brand new coders who don’t know how to write basic loops yet, but once you learn the fundamentals this is a great site to practice coding.

There are free challenges available on LeetCode, and they also have a premium subscription which gets you access to more challenges and other features of the platform.

Helpful links: Website | Blog | Challenges

Image

This is the first time Edabit is appearing on our top sites list ( 2018 list , 2017 list )! It has grown in popularity over the last year, and developers seem to really enjoy the challenges. They offer a large collection of over 4,000 challenges that can be solved online in one of several languages.

The site currently only offers online interactive coding challenges — there aren’t any discussion boards, articles, user solutions, or mock interviews like other sites offer, but over time they might be adding some of these.

Edabit is great for beginners looking to practice their coding skills daily by solving bite-sized challenges. Once you reach the intermediate stage, other sites provide harder challenges and more content geared towards competitive programming and job interviews.

All the challenges on Edabit are free, and there is no premium pricing option.

5. Codewars

Helpful links: Website | Blog | Free Challenges | Premium

Image

Codewars provides a large collection of coding challenges submitted and edited by their own community. You can solve the challenges directly online in their editor using 20+ programming languages. You can view a discussion for each challenge as well as user solutions. You can earn points and climb the rankings by solving their challenges.

Codewars is great for people in the beginner-to-intermediate phase. The challenges are created by the community so you get exposed to a lot of different types of coding challenges.

They offer all of their challenges created by the community for free, and their premium subscription gets you access to some cool features on their platform.

6. HackerRank

Image

HackerRank has a large collection of coding challenges tailored towards algorithms and data structures, along with interview prep material, a discussion board for each challenge, and a list of top user solutions. They have challenges for other topics as well like functional programming, AI, Shell, SQL, and more.

HackerRank is great for intermediate-to-advanced programmers who have already picked up the basics of a language and are ready to solve more complicated problems. The challenges are written with mathematical notation and can sometimes be a little confusing, which is why it might not be so great for beginner developers.

All the challenges on HackerRank are free, and there is no premium pricing option.

7. TopCoder

Image

TopCoder is one of the original platforms for competitive programming online. It provides a list of algorithmic challenges from past competitions that you can complete on your own directly online using their code editor.

Their popular Single Round Matches are offered a few times per month at a specific time where you compete against others to solve challenges. Here are some topics that their challenges may cover.

Aside from solving challenges for fun online, they offer sponsored competitions where you can win prizes for writing the best solution.

TopCoder is better suited for advanced programmers who are comfortable solving algorithm challenges dealing with advanced topics like graph search and number theory.

All the challenges on TopCoder are free, and there is no premium pricing option.

8. Codeforces

Helpful links: Website | Discussion | Challenges

Image

Codeforces is now probably the top competitive programming website (a few years ago TopCoder was where most competitive programmers spent their time).

There are problems that you can solve online to practice, but there’s no online editor. Rather, you write your solution in your own editor and then upload it to their system which then tests your code against a suite of test cases.

They also frequently hold contests where the best competitive programmers take part in.

Advanced and competitive programmers who truly enjoy solving difficult algorithm challenges.

All the challenges on Codeforces are free, there is no premium pricing option.

If you read this far, thank the author to show them you care. Say Thanks

Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started

IMAGES

  1. 6 Ways to Improve Your Programming Problem Solving

    problem solving with coding

  2. How to Solve Coding Problems with a Simple Four Step Method

    problem solving with coding

  3. How To Approach A Coding Problem ?

    problem solving with coding

  4. Problem Solving In Programming

    problem solving with coding

  5. computer algorithm science problem solving process with programming

    problem solving with coding

  6. Tips for Improving Your Coding Problem-Solving

    problem solving with coding

VIDEO

  1. Find how many Digits in Given Number

  2. Problem A Codeforces Round 976 (Div. 2) and Divide By Zero 9.0

  3. A Simple Technique to Solve Coding Problems

  4. Open Closed Door Problem

  5. Two Numbers

  6. Bit++ Codeforces Solution (Arabic) || Java || 282A

COMMENTS

  1. Problems

    Boost your coding interview skills and confidence by practicing real interview questions with LeetCode. Our platform offers a range of essential problems for practice, as well as the latest questions being asked by top-tier companies.

  2. Online Coding Practice Problems & Challenges

    Welcome to Practice! Practice over 5000+ problems and challenges in coding languages like Python, Java, JavaScript, C++, SQL and HTML. Start with beginner friendly challenges and solve hard problems as you become better. Use these practice problems and challenges to prove your coding skills. Old practice page Recent Contest Problems.

  3. The 10 Most Popular Coding Challenge Websites

    By Daniel Borowski. A great way to improve your skills when learning to code is by solving coding challenges. Solving different types of challenges and puzzles can help you become a better problem solver, learn the intricacies of a programming language, prepare for job interviews, learn new algorithms, and more.

  4. How to Solve Coding Problems with a Simple Four Step Method

    In this post, we've gone over the four-step problem-solving strategy for solving coding problems. Let's review them here: Step 1: understand the problem. Step 2: create a step-by-step plan for how you'll solve it. Step 3: carry out the plan and write the actual code.

  5. Basic Programming Problems

    Learn Programming - How To Code. In the world of programming, mastering the fundamentals is key to becoming a proficient developer.In this article, we will explore a variety of basic programming problems that are essential for every aspiring coder to understand. By delving into these foundational challenges, you will gain valuable insights into problem-solving techniques and build a strong ...

  6. 10,000+ Coding Practice Challenges // Edabit

    Practice coding with fun, bite-sized challenges. Earn XP, unlock achievements and level up. It's like Duolingo for learning to code.

  7. Practice

    Support in All Problems, 35+ Courses, Text-Summarisation, Ad-Free Learning & much more. Go Premium. Platform to practice programming problems. Solve company interview questions and improve your coding intellect.

  8. How To Approach A Coding Problem

    These steps you need to follow while solving a problem: - Understand the question, read it 2-3 times. - Take an estimate of the required complexity. - find, edge cases based on the constraints. - find a brute-force solution. ensure it will pass. - Optimize code, ensure, and repeat this step.

  9. Programming Tutorials and Practice Problems

    If playback doesn't begin shortly, try restarting your device. Practice programming skills with tutorials and practice problems of Basic Programming, Data Structures, Algorithms, Math, Machine Learning, Python. HackerEarth is a global hub of 5M+ developers.

  10. Solve Python

    Problem Solving (Basic) Python (Basic) Problem Solving (Advanced) Python (Intermediate) Difficulty. Easy. Medium. Hard. Subdomains. Introduction. Basic Data Types. Strings. Sets. Math. ... Join over 23 million developers in solving code challenges on HackerRank, one of the best ways to prepare for programming interviews.

  11. The Most Popular Coding Challenge Websites

    Now, coding/programming isn't just about solving different kinds of problems using different programming languages, but it's a large part of what you'll do as a developer. The fields of Web development, Machine Learning, Artificial Intelligence, Augmented Reality, App Development, and many others require strong problem-solving skills.

  12. 20 Code Challenges To Put What You're Learning to the Test

    Code challenges help you build problem-solving skills, better understand the programming language you use, and get to know algorithms you may not be familiar with. If you want to improve your skills in programming, there's no better way than by writing code. ... By having you solve a coding challenge, they can assess your skills and be sure ...

  13. Coding Games and Programming Challenges to Code Better

    Solve games, code AI bots, learn from your peers, have fun. CodinGame is a challenge-based training platform for programmers where you can play with the hottest programming topics. Solve games, code AI bots, learn from your peers, have fun.

  14. Codewars

    Solve kata with your coding style right in the browser and use test cases (TDD) to check it as you progress. Retrain with new, creative, and optimized approaches. Find all of the bugs in your programming practice. Earn ranks and honor. Kata code challenges are ranked from beginner to expert level. As you complete higher-ranked kata, you level ...

  15. 12 JavaScript Code Challenges for Beginners

    6. Sort an array from lowest to highest. You could create a function for this solution as well, but be sure to try your program with varying lengths and types of arrays. Try one with all integers, another with negative numbers, and another with decimals. 7. Create a function that filters out negative numbers.

  16. Solve C

    Solve Challenge. Join over 23 million developers in solving code challenges on HackerRank, one of the best ways to prepare for programming interviews.

  17. Solve Java

    Problem Solving (Intermediate) Difficulty. Easy. Medium. Hard. Subdomains. Introduction. Strings. BigNumber. Data Structures. Object Oriented Programming. Exception Handling. Advanced. ... Join over 23 million developers in solving code challenges on HackerRank, one of the best ways to prepare for programming interviews.

  18. All Practice Problems

    Improve your programming skills by solving problems on topics like arrays, sorting etc. Get access to a large repository of problems on all the data structures and algorithms out there. Learn Programming and Practice Coding Problems with CodeChef. Improve your programming skills by solving problems on topics like arrays, sorting etc. Get access ...

  19. How to think like a programmer

    Simplest means you know the answer (or are closer to that answer). After that, simplest means this sub-problem being solved doesn't depend on others being solved. Once you solved every sub-problem, connect the dots. Connecting all your "sub-solutions" will give you the solution to the original problem. Congratulations!

  20. Solving 'The Change-making problem' with a formula

    The Change-making problem. I have seen this problem appear on many coding challenge web sites. There are variations of the Change-making problem such as "The Coin Problem" or "The Coin Collector's Problem", etc. For this task, I decided to use US currency (and even included denominations no longer in print to make things interesting.). The Rules

  21. Learn to Solve Vehicle Routing Problems ASAP: A Neural Optimization

    Finding a feasible and prompt solution to the Vehicle Routing Problem (VRP) is a prerequisite for efficient freight transportation, seamless logistics, and sustainable mobility. Traditional optimization methods reach their limits when confronted with the real-world complexity of VRPs, which involve numerous constraints and objectives. Recently, the ability of generative Artificial Intelligence ...

  22. The 8 Best Coding Challenge Websites to Help You Level Up Your Skills

    2. Coderbyte. Helpful links: Website | Blog | Dev.to | Free Challenges | Premium. My platform, Coderbyte, provides 300+ coding challenges you can solve in an online editor using 10 different programming languages. You can then access official solutions, over 1.5 million user solutions, and read articles on how to efficiently solve the challenges.

  23. Solve PC problems remotely using Quick Assist

    Select Help someone, then share the 6-digit code with the person you're helping. After they've entered the code, wait for the person you're helping to allow the connection and share their screen. When you're connected and helping someone, you can use different tools in Quick Assist if you like, such as a laser pointer, annotation, chat for ...