0% found this document useful (0 votes)
40 views

Python leetcode solution 2

Uploaded by

Biji CL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Python leetcode solution 2

Uploaded by

Biji CL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

An approach

to
programmin
g
Akshay Sankar
[22BCE0286]
Problem Statement

Various Approaches
“Bad” to “less bad” “Good” to “Better”

 Code is inefficient  Code is efficient

 The inefficient code can be  This code can be improved by using


improved but it will still be better algorithms or data structures
inefficient if it based on bad code
Inefficient Code
 Many loops.

 Unwanted conditions

 Lots of variables
Good Inefficient Code
 Lesser loops

 Still has unwanted


conditions

 Number of variables is same


Comparison
Inefficient Code Good Inefficient Code
Explanation
Attempting to create good code
  Using string commands to
optimize the code

 Throws an error when the


character isn’t found and
therefore, doesn’t pass all
testcases.
Good Code
 Using a try and except block

 If an error is thrown, the


code goes to the except
block
Better Code
 Optimizing by removing
variables
Explanation
Comparison
Good Code Better Code
Comparison
Inefficient Code Better Code
Efficient Code
Types of Efficiency
Time Efficient Memory Efficient
 This type of code uses more  This type of code might take longer
variables but performs lesser to execute but uses lesser memory
calculations.  Using many calculations means that
 If the exact same calculation is used lesser memory is used to store the
somewhere, then using a variable result of those calculations
instead of calculation in its place
increases time efficiency
Comparison
Time Efficient Memory Efficient
Thank you

You might also like